我试图使用requests
库构建python爬虫。当我使用get
方法检索结果如下:THá» THAO
。但是当我使用curl
时,我得到了THỂ THAO
,这是我的预期结果。这里是我的代码:Python - 使用curl和请求库时检索到不同结果
def get_raw_channel():
r = requests.get('http://vtv.vn/')
raw_html = r.text
soup = BeautifulSoup(raw_html)
o_tags = soup.find_all("option")
for o_tag in o_tags:
print o_tag.text
# raw_channel = RawChannel(o_tag.text.strip(), o_tag['value'])
# channels_file.write(raw_channel.__str__() + '\n')
这里是我的卷曲CMD:curl http://vtv.vn/
问:为什么结果不同呢?我如何使用requests
实现curl
的结果?
什么是响应体的编码? – 2015-02-09 08:17:05
@LutzHorn '(Date:Mon,09 Feb 2015 07:59:34 GMT,Content-Type:text/html,Transfer-Encoding:chunked,Connection:close,Vary:Accept-Encoding,Server:vtv-rp' 这是curl响应头。和: '{'via':'1.1 TMG','proxy-connection':'Keep-Alive','transfer-encoding':'chunk ed','vary':' Accept-Encoding','server':'vtv-rp','connection':'Keep-Alive', 'date':'Mon,09 Feb 2015 08:19:52 GMT','content-type': 'text/html'}'是请求响应头。 – 2015-02-09 08:20:25
@LutzHorn我没有看到响应的编码,但我认为它是'utf-8' – 2015-02-09 08:22:28