Re: [問題] 用requests.post爬蟲 以及編碼的問題

作者: iPhone007 (iPhone007)   2016-07-02 00:18:55
用以下的方法硬解,雖然方法不是很好,不過似乎是可以解出資料
看是不是能拋磚引玉,請其他大大提出好的解法
input_year = '105'
input_month = '06'
import requests
url='http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php'
payload = {
'myear':input_year,
'mmon':input_month
}
res = requests.post(url, data = payload)
from bs4 import BeautifulSoup
res.encoding = 'big5'
idx_bgn = res.text.index(u"<div align=center class=til_2>")
idx_end = res.text.index(u"<!
作者: akpipnlge (akpipnlge)   2016-07-02 06:38:00
因為我只是要取數據而已,只要去tag就好所以beautifulsoup雖然不過,但是其他套件可以一個不求甚解XDDD
作者: s860134 (s860134)   2016-07-02 11:18:00
用 lxml 應該可以很好的爬出 tag 結構
作者: iPhone007 (iPhone007)   2016-07-02 12:01:00
感謝分享 ^_^

Links booklink

Contact Us: admin [ a t ] ucptt.com