我的代码返回HTTP错误403:禁止 [英] My code returns HTTP Error 403: Forbidden
本文介绍了我的代码返回HTTP错误403:禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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被禁止,我查找了其他结果,但它们与我的代码编写方式不符
I'm trying to access a page to start scraping it, but it replies that the HTTP is forbidden, I looked up other results, but they don't match up with how I'm doing my code
推荐答案
由于您的用户代理,您被阻止了.尝试像这样欺骗您的用户代理:
You are being blocked because of your User Agent. Try spoofing your User Agent like this:
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)
这篇关于我的代码返回HTTP错误403:禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文