2015年10月28日 星期三

[python] python爬網頁資料

工具: requests: http://docs.python-requests.org/en/latest/ 送出http請求 BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/bs4/doc/ 分析抓回來的html原始碼 範例: import requests from BeautifulSoup import BeautifulSoup url = "http://ocg.xpg.jp/search/search.fcgi?CardNo=1&Record=1" res = requests.get(url, verify=False) soup = BeautifulSoup(''.join(res)) titlename = soup.find('title').string table1 = soup.find(class_="Hover w9") for row in table1.findAll('tr'): col = table1.findAll('td') day = col[0].string cheap = col[2].string top = col[3].string print titlename

沒有留言:

張貼留言