其他分享
首页 > 其他分享> > 爬虫-获取内陆明星

爬虫-获取内陆明星

作者:互联网

# -*-coding:utf-8-*-
import requests
import math
import json


if __name__ == "__main__":
count = "100"
page_count = math.ceil(26148/100)
with open("b.txt", "a+") as f:
for x in range(page_count):
pn = 100 * x
url = "https://sp1.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=28266&from_mid=1&&format=json&ie=utf-8&oe=utf-8&query=%E5%86%85%E5%9C%B0%E6%BC%94%E5%91%98&sort_key=&sort_type=1&stat0=&stat1=%E5%86%85%E5%9C%B0&stat2=&stat3=&pn="\
+ str(pn) + "&rn=" + count + "&cb=jQuery110209517875148423749_1654675051861&_=1654675051862"
r = requests.get(url=url)
if str(r.status_code).startswith("20"):
json_str = "".join(r.text.replace("jQuery110209517875148423749_1654675051861(", "")[:-1])
data = json.loads(json_str)["data"][0]["result"]
for item in data:
f.write(item["ename"] + "\r\n")
print(item["ename"])

标签:__,count,E5%,内陆,爬虫,获取,json,str,pn
来源: https://www.cnblogs.com/fuchenjie/p/16356491.html