【发布时间】:2018-04-05 17:21:38
【问题描述】:
我正在尝试使用 HTML 解析器使用 Python3.6 解析网站,但它会引发如下 ab 错误:
urllib.error.HTTPError:HTTP 错误 302:HTTP 服务器返回一个重定向错误,这将导致无限循环。 最后的 30x 错误消息是: 找到 我写的代码如下: {
from urllib.request import urlopen as uo
from bs4 import BeautifulSoup
import ssl
# Ignore SSL Certification
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = input('Enter--')
html = uo(url,context = ctx).read()
soup = BeautifulSoup(html,"html.parser")
print(soup)
#retrieve all the anchor tags
#tags = soup('a')
}
谁能告诉我为什么会抛出这个错误,这是什么意思以及如何解决这个错误?
【问题讨论】:
-
听起来像是服务器错误。你能给我们你要连接的网址吗?
-
该站点设置 cookie,然后重定向到 /Home.aspx。你需要一个 cookie 容器。
标签: python-3.x beautifulsoup urllib html-parser