from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
myUrl = "https://mee6.xyz/levels/159962941502783488"
uClient = uReq(myUrl)
pageHtml = uClient.read()
print("pageHtml)我试图访问一个页面来开始抓取它,但是它回答说HTTP是被禁止的,我查找了其他的结果,但是它们与我的代码不匹配
发布于 2018-06-07 18:18:36
因为您的用户代理,您被阻塞了。尝试像这样欺骗您的用户代理:
from urllib.request import urlopen as uReq
from urllib.request import Request
from bs4 import BeautifulSoup as soup
myUrl = "https://mee6.xyz/levels/159962941502783488"
req = Request(
myUrl,
data=None,
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
}
)
uClient = uReq(req)
pageHtml = uClient.read()
print(pageHtml)https://stackoverflow.com/questions/50746909
复制相似问题