Hy! 브라우저에서 열리는 웹 페이지를 열려고했지만 파이썬은 단지 맹세하고 작동하지 않으려 고합니다. 다시 urllib.error.HTTPError : HTTP 오류 400 : 잘못된 요청
import urllib.request, urllib.error
f = urllib.request.urlopen('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphire')
그리고
import urllib.request, urllib.error
opener=urllib.request.build_opener()
f=opener.open('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphi
re')
두 옵션은 오류의 한 종류 제공하는 또 다른 방법 :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\urllib\request.py", line 461, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 493, in error
result = self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 676, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Python34\lib\urllib\request.py", line 461, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 499, in error
return self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 579, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
어떤 아이디어?
고맙습니다 만, 'from urllib import FancyURLopener'를 'urllib.request import FancyURLopener'(오류였습니다)로 변경했습니다. 그리고 결국에는 다음 오류가 발생합니다 ('>>> page.read()'실행 후) : ValueError : 닫힌 파일을 읽습니다. – Wanu
그래서 버전 = 'My new User-Agent'를 Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv : 1.8.1.11) Gecko/20071127 Firefox/2.0.0.11 '으로 변경했습니다. 그리고 그 오류는 사라졌습니다! 매우 큰 감사합니다! 나는이 문제에 대한 해결책을 오랫동안 찾고 있었고, 당신은 나를 많이 도왔습니다! – Wanu