我正在尝试获取一个TikTok视频页面的HTML,请求返回b'‘而不是整个html页面。这在其他站点甚至tiktok主页(https://www.tiktok.com/)上都有效,但在视频页面上不起作用。有人能试一下我的代码然后告诉我发生了什么吗?另外,我得到了返回码,是200。
import requests
headers = {
'user-agent': MY USER AGENT,
}
page = requests.get("https://www.tiktok.com/@thatlittlepuff/video/7160116843611475246",headers=headers)
print(page.content)b''我试过做其他tiktok视频页面,但它们也不起作用
发布于 2022-11-06 06:32:43
如果您不能使用创建令人信服的标头,可以考虑使用类似于ScrapingAnt的东西
api_url = "https://api.scrapingant.com/v2/general"
page_url = "https://www.tiktok.com/@thatlittlepuff/video/7160116843611475246"
myKey_sa = YOUR_API_TOKEN # register on https://scrapingant.com/ and paste here
page = requests.get(f'{api_url}?url={page_url}&x-api-key={myKey_sa}')
print(page.content)空闲层允许有限数量的请求,而且速度很慢,但是如果您不会发出大量的请求,那么它确实简化了一些事情。
如果要发出大量请求,请考虑使用硒。
https://stackoverflow.com/questions/74310329
复制相似问题