Clearpython 发表于 2020-7-2 15:21:42

尝试爬取今日头条--成功了


import requests
import json

url = 'https://www.toutiao.com/api/pc/realtime_news/'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.58'
}

response = requests.get(url,headers=headers).text
json_data = json.loads(response)
r = json_data["data"]
print(r)
j = 1
for i in r:
    print(j,"https://www.toutiao.com/a"+i["open_url"][7:],i["title"])
    j += 1
页: [1]
查看完整版本: 尝试爬取今日头条--成功了