python3爬虫入门程序
Posted 凉云
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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, ‘ ‘, phone, ‘ ‘, status_code, ‘
‘, user_agent)
db.close()
以上是关于python3爬虫入门程序的主要内容,如果未能解决你的问题,请参考以下文章