import MySQLdb
import requests
num = 1713
n = 0
url = "http://wsgg.sbj.cnipa.gov.cn:9080/tmann/annInfoView/annSearchDG.html"
headers = {
'user-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'
}
for annnum in range(50):
data = {
'page':'1',
'rows':'400000',
'annNum':str(num),
'annType':'',
'tmType':'',
'coowner':'',
'recUserName':'',
'allowUserName':'',
'byAllowUserName':'',
'appId':'',
'appIdZhiquan':'',
'bfchangedAgengedName':'',
'changeLastName':'',
'transferUserName':'',
'acceptUserName':'',
'regName':'',
'tmName':'',
'intCls':'',
'fileType':'',
'totalYOrN':'true',
'appDateBegin':'',
'appDateEnd':'',
'agentName':'',
}
num -= 1
print(data)
res = requests.post(url,data=data,headers=headers).json()
conn = MySQLdb.connect(
host='localhost',
port=3306,
user='root',
password='123456',
db='spider',
charset='utf8'
)
cursor = conn.cursor()
for i in res['rows']:
try:
sql = 'INSERT IGNORE INTO brand1 VALUES(%s,%s,%s)'
cursor.execute(sql, [i['tm_name'], i['reg_num'], i['reg_name']])
conn.commit()
n += 1
print(n)
except Exception as e:
print(f'存入数据失败,原因:{e}')