美好的一天!
在python 3 *中编写了以下代码,它给出了一堆错误:
from html.parser import HTMLParser
import re
from urllib.request import urlopen
import glob
your_hotel_adres="http://www.booking.com/hotel/ua/boutique-hotel-kavalier.ru.html"
your_hotel_сс1=your_hotel_adres[29:31]
your_hotel_pagename=''
i = 30
while i <= len(your_hotel_adres):
i = i + 1
if your_hotel_adres[i:i+5] == ".html":
your_hotel_pagename=your_hotel_adres[32:i-3]
break
your_hotel_comm="http://www.booking.com/reviewlist.ru.html?pagename="+your_hotel_pagename+";cc1="+your_hotel_сс1+";type=total;dist=1;offset=0;rows=1000"
f = urlopen(your_hotel_comm)
它应该下载一个网页并将其写入变量。所以我运行它,并得到很多错误:
>>> f=urlopen('http://www.booking.com/reviewlist.ru.html?pagename=boutique-hotel
-kavalier;cc1=ua;type=total;dist=1;offset=0;rows=1000')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\urllib\request.py", line 153, in urlopen
return opener.open(url, data, 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 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
请帮帮我! 刚注意到一件事:打开的页面的vbrauzere地址,有以下形式: http://www.booking.com/reviewlist.ru.html?pagename=boutique-hotel-kavalier;cc1=ua;type=total;dist=1;offset=0;rows=1000 和地址,生成我的代码: http://www.booking.com/reviewlist.ru.html?pagename=boutique-hotel -kavalier; CC1 = UA;类型=总; DIST = 1;偏移= 0;行= 1000 如何解决?