我正在阅读一本关于Web Scraping with Python的书,我试着这样做:
当我尝试这个时:
SELECT TOP 1000 *
FROM [tisonline].[dbo].[Jobs] AS j
LEFT OUTER JOIN [tisonline].dbo.JobQueries AS jq
ON j.JobID = jq.JobID
LEFT OUTER JOIN [tisonline]. dbo.Agents AS agt ON agt.AgentID = jq.AgentID
where j.isMigrated = 1
OR (j.isMigrated = 0 AND jp.JobID IS NOT NULL AND agt.AgentID IS NOT NULL)
当我运行它时,我有以下错误:
from urllib.request import urlopen
from bs4 import BeautifulSoup
from urllib.error import HTTPError
html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html")
except urllib.error.HTTPError as e:
print(e.code)
if html is none:
print("url is not found")
else:
bsObj = BeautifulSoup(html.read());
print(bsObj
我也试过"除了urllib.HTTPError"在第6行没有任何成功。
我做错了什么?
答案 0 :(得分:2)
您错过了try
声明
from urllib.request import urlopen
from bs4 import BeautifulSoup
from urllib.error import HTTPError
try:
html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html")
except urllib.error.HTTPError as e:
print(e.code)
if html is None:
print("url is not found")
修改:您还应将none
更改为None