今天无意间找到了今日头条热搜的接口链接,顺手写了一个爬取今日头条热搜的爬虫,并保存到excel中
python
import json
import re
import openpyxl
import requests
from lxml import etree
wb = openpyxl.Workbook()
ws = wb.active
ws.append(['顺序','热搜分类','热搜关键词'])
url = requests.get("https://www.toutiao.com/hot-event/hot-board/?origin=toutiao_pc&_signature=_02B4Z6wo00f01yG9tdQAAIDCQrd1vxaJp9chmbFAAKpR4Dqk0c56dkhdlvNsoD3I03ygIjgUcxkM0VcFYKfO0a9iJRjnl1M9yxZvlq-pgzUXDOrpi1wKoYlCVC9.llzChJ7GmTYXIDMvE.c1a6")
data = json.loads(url.text)['data']
print("data:",data)
for i in data:
try:
print(f'热搜:{i["Title"]}, 链接为:{i["Url"]},热度:{i["HotValue"]},')
ws.append([i["Title"],i["Url"],i["HotValue"]])
except:
pass
wb.save("今日头条热搜.xlsx")