【更新中】Hotspot tracer
Hotspot Follower
闲着没事,打算做一个爬取社会热点的项目,首先通过微信搜狗进行分析。
代码基于PYTHON
import requests
import json
def page(startPage, endPage):
for i in range(startPage-1, endPage):
print("当前是第%s页" % (i-1))
url="https://www.toutiao.com/api/search/content/?aid=24&app_name=web_search&offset={}&format=json&keyword=%E5%8F%A3%E7%BD%A9&autoload=true&count=20&en_qc=1&cur_tab=1&from=search_tab&pd=synthesis×tamp=1580891440999".format(i*20)
isPage = loadPage(url)
if isPage == False :
return
def loadPage(url):
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
"cookie": "tt_webid=6788464205051397645; csrftoken=0fe8163308489633ff71b3e6b5cb83d6; tt_webid=6788464205051397645; s_v_web_id=k691xn0o_XIr45KJy_l5va_4B5f_BRm7_dM5ZykD2FblR; WEATHER_CITY=%E5%8C%97%E4%BA%AC; __tasessionId=i33adfilb1580891422290"
}
try:
data = requests.get(url, headers=headers).text
news = json.loads(data)
for new in news["data"]:
if "title" in new.keys():
print(new["title"])
except Exception as e:
print(e)
return False
return True
if __name__ == '__main__':
startPage = int(input("请输入起始页码"))
endPage = int(input("请输入终止页码"))
page(startPage, endPage)
输出如下: