Re: [问题] 台银汇率爬虫问题

楼主: iPhone007 (iPhone007)   2016-06-28 21:56:11
※ 引述《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
作者: f0987654 (skywalker)   2016-06-28 22:23:00
刚刚测试一下可以了,感谢!!

Links booklink

Contact Us: admin [ a t ] ucptt.com