我試圖使用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