python3爬虫入门程序
2021-06-30 08:04
标签:flat enc root value sql pymysql data orm python3 import pymysql f = Faker(locale="zh-CN") def duang(): if name == ‘main‘: python3爬虫入门程序 标签:flat enc root value sql pymysql data orm python3 原文地址:https://www.cnblogs.com/liangyun/p/9642962.html
import requests
import json
from faker import Faker
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
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()
上一篇:09类的继承(Java)
下一篇:python猜数字小游戏