python3爬虫入门程序

2021-06-30 08:04

阅读:668

标签:flat   enc   root   value   sql   pymysql   data   orm   python3   

import pymysql
import requests
import json
from faker import Faker

f = Faker(locale="zh-CN")

def duang():
user_agent = f.user_agent()
phone = f.phone_number()
url = r"https: // download.zslxt.com / tinterface.php"
headers = {
"Host": "download.zslxt.com",
"User-Agent": user_agent,
"Accept": "/",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate, br",
"Referer": "http:/gpyd.gp241.com/nyqpc/bd2.html?id=20110052",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Content-Length": "107",
"Origin": "http://gpyd.gp241.com",
"Connection": "keep-alive"
}
data = {
"bm": "gbk",
"gpdm": "",
"id": "20110052",
"phone": phone,
"qudao": 98,
"remarks": "牛有圈百度2)"
}

req = requests.post(url=url, headers=headers, data=json.dumps(data))
return user_agent, phone, req.status_code

if name == ‘main‘:
for i in range(100000):
user_agent, phone, status_code = duang()
db = pymysql.connect("localhost", "root", "xiaoyan", "python")
cur = db.cursor()
cur.execute(f"INSERT INTO python1duang VALUES(default,‘{user_agent}‘,‘{phone}‘,‘{status_code}‘)")
db.commit()
print(i, ‘\t‘, phone, ‘\t‘, status_code, ‘\n‘, user_agent)
db.close()

python3爬虫入门程序

标签:flat   enc   root   value   sql   pymysql   data   orm   python3   

原文地址:https://www.cnblogs.com/liangyun/p/9642962.html


评论


亲,登录后才可以留言!