爬虫-获取内陆明星

# -*-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"])

posted @ 2022-06-08 17:23  你看起来真的很好吃  阅读(64)  评论(0编辑  收藏  举报