我正在使用 aiohttp 来抓取不同的网站。对于大多数网站,我的代码运行良好,但对于https://bestbuy.com/,我的代码甚至无法打印响应代码。有谁知道这是为什么?
我的代码
import asyncio
import aiohttp
head = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'}
async def myDriver():
await httpBestBuy("https://www.amazon.com/")
await httpBestBuy("https://www.bestbuy.com/")
async def httpBestBuy(URL):
async with aiohttp.ClientSession(headers = head) as session:
async with session.get(URL) as page:
print(page.status)
asyncio.run(myDriver())
输出
200
我只是想了解为什么它不会为百思买抛出任何错误;它只是不打印任何东西。提前感谢您的帮助:)
笔记
- 蟒蛇 3.7.9
- Aiohttp 3.6.3
- 我试过有标题和没有标题,没有区别