Ibt*_* Ch 1 python web-scraping python-requests
我一直在尝试使用https://www.dickssportinggoods.com/f/tents-accessories 请求模块访问该网站,但它只是继续处理并且不会停止,而同一网站在浏览器上运行良好。Scrappy 给出了同一网站的超时错误。访问此类网站时有什么需要注意的吗?谢谢
对于此类网站,您可以尝试添加浏览器所做的额外标头。遵循这些步骤对我有用 -
供参考的图片 - https://i.stack.imgur.com/vRS98.png
编辑 -
import requests
headers = {
'authority': 'www.dickssportinggoods.com',
'pragma': 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
'sec-ch-ua-mobile': '?0',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'sec-fetch-site': 'none',
'sec-fetch-mode': 'navigate',
'sec-fetch-user': '?1',
'sec-fetch-dest': 'document',
'accept-language': 'en-US,en;q=0.9',
}
response = requests.get('https://www.dickssportinggoods.com/f/tents-accessories', headers=headers)
print(response.text)
Run Code Online (Sandbox Code Playgroud)