我想使用python访问一个网站
AsyncHTMLSession
从…起
requests_html
图书馆
这是我的代码:
from requests_html import AsyncHTMLSession
import asyncio
async def connect_to_site(url):
session = AsyncHTMLSession()
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}
res = await session.get(url, headers=headers)
print(res)
await res.html.arender(sleep=5, timeout=30)
print(res.html.full_text)
url = 'https://www.otcmarkets.com'
asyncio.run(connect_to_site(url))
执行代码后,我得到以下打印:
<回应[200]>
拒绝访问
拒绝访问
你没有权限访问“http://www.otcmarkets.com/“在这个服务器上。
参考#18.9c4519d4。1643149046.338b64e3
可能是什么问题?我怎样才能克服它?