문제
내가 사용하여 이 간단한 코드
for l in bios:
OpenThisLink = url + l
response = urllib2.urlopen(OpenThisLink)
에 대해 열 200url 과 검색으로 그들을 정규식(및 BeautifulSoup),하지만 그 후에 그래서 나는 이러한 오류 및 유휴가 종료됩니다.그들은 무엇을 의미합니까?어떻게 관리할 수 있을까?
감사합니다.
Traceback (most recent call last):
File "\PROJECTS\JD\jd10.py", line 15, in <module> response = urllib2.urlopen(OpenThisLink)
File "C:\Python26\lib\urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 389, in open response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 502, in http_response 'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 421, in error result = self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain result = func(*args)
File "C:\Python26\lib\urllib2.py", line 597, in http_error_302 return self.parent.open(new)
File "C:\Python26\lib\urllib2.py", line 389, in open response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 502, in http_response 'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 421, in error result = self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain result = func(*args)
File "C:\Python26\lib\urllib2.py", line 597, in http_error_302 return self.parent.open(new)
File "C:\Python26\lib\urllib2.py", line 389, in open response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 502, in http_response 'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 427, in error return self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain result = func(*args)
File "C:\Python26\lib\urllib2.py", line 510, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 404: Not Found
해결책
오류 발생되는 것입 HTTPError
특히,404 은 발생되는 하나의 Url 이 있습니다.할 수 있는 하나 그것을 무시:
for l in bios:
OpenThisLink = url + l
try:
response = urllib2.urlopen(OpenThisLink)
except urllib2.HTTPError:
pass
또는,당신은 다시 올리에 오류가(소폭)더 의미 있는 메시지:
for l in bios:
OpenThisLink = url + l
try:
response = urllib2.urlopen(OpenThisLink)
except urllib2.HTTPError as e:
raise Exception('Error opening %s: %s' % (e.geturl(), e))
다른 팁
나는 아무것도 몰라에 대해 특정 라이브러리는 당신이 사용합니다.그러나,이것 같이 하나의 큰 스택 추적에 이르게 하는 원래 오류가 끝:
HTTPError:HTTP Error404:발견되지 않았
나는 생각한 링크 중 하나를 나쁘고 유발하는 예외 없었다.
편집:의"나"내 말은 페이지를 할 수 없을 검색하여 서버,따라서 404 오류가 있습니다.
제휴하지 않습니다 StackOverflow