Re: [問題] 台銀匯率爬蟲問題

看板Python作者 (iPhone007)時間9年前 (2016/06/28 21:56), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《f0987654 (skywalker)》之銘言: : 最近想用python練習抓台銀的匯率資料來做一些研究,不過遇到了一些問題 : 我的目標頁面是這頁的匯率資訊 : https://fctc.bot.com.tw/Purchase/SelectCurrencyBank : 之前用chrome的開發者工具研究了一下, 正常操作流程會是這樣 : step 1. GET https://fctc.bot.com.tw/Purchase/WarningPage : step 2. GET https://fctc.bot.com.tw/Purchase/RequestNewOrder : step 3. POST https://fctc.bot.com.tw/Purchase/SelectCurrencyBank : 我嘗試過拿step1, step2 的form 資料(變數__RequestVerificationToken)POST 到step3 : 也是會一直錯誤,它並不會吐匯率資料出來 : 想說各位有經驗的大大,請問這要如何處理呢? : 感謝 : 環境:python 2.7.10 : 套件: requests, urllib, BeautifulSoup 抱歉,剛剛推文有誤 重試以下的程式,應該是ok #Step1 #從 https://fctc.bot.com.tw/Purchase/WarningPage 取得__RequestVerificationToken import requests rs = requests.session() res = rs.get('https://fctc.bot.com.tw/Purchase/WarningPage#') from bs4 import BeautifulSoup soup = BeautifulSoup(res.text) token = soup.select('input')[0].get('value') #Step2 #做POST取回資料 payload = { '__RequestVerificationToken':token } res2 = rs.post('https://fctc.bot.com.tw/Purchase/SelectCurrencyBank', data = payload) print res2.text -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.26.109.76 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1467122174.A.0BC.html

06/28 22:23, , 1F
剛剛測試一下可以了,感謝!!
06/28 22:23, 1F
文章代碼(AID): #1NSe7-2y (Python)
討論串 (同標題文章)
文章代碼(AID): #1NSe7-2y (Python)