当我尝试使用以下配置时:
当我尝试这个时:
Sequence: 1
GroupValue: 00000000000100
我收到以下错误:
from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup
try:
html = urlopen("http://www.pythonscraping.com/pages/pages1.html")
if html is None:
print("url not found")
else:
except HTTPError as e:
print("test")
else:
bsObj = BeautifulSoup(html.read())
print(bsObj)
我做错了什么?
答案 0 :(得分:1)
感谢您的提示,我找到了解决问题的方法:
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup
try:
html = urlopen("http://www.pythonscrapng.com/pages/pages1.html")
bsObj = BeautifulSoup(html.read())
print(bsObj)
except HTTPError as e:
print("test")
except URLError as j:
print ("No URL")
else:
bsObj = BeautifulSoup(html.read())
print(bsObj)