[問題] 寫crawler但抓不到ajax post網頁
作者: justin760204 (華華) 看板: R_Language
標題: [問題] 寫crawler但抓不到ajax post網頁
時間: Sat Aug 22 01:52:28 2015
ctrl + y 可以刪除一整行,請將不需要的內容刪除
文章分類提示:
- 問題: 小弟希望用R寫一個能夠自動上網抓取上市公司財報並做分析的程式
不過寫抓資料的程式遇到了瓶頸無法突破, 拜託各位大大指點迷津
Cockie及Referer均已加入但Server仍無Reply
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
請把以下不需要的部份刪除
入門(寫過其他程式,只是對語法不熟悉)
[問題敘述]:
請簡略描述你所要做的事情,或是這個程式的目的
[程式碼]
library(XML)
library(RCurl)
# 設定Coockie參數
curlHandle = getCurlHandle()
# 進入公開資訊觀測站XBRL綜合損益表網頁抓取Coockie
url = URLencode("http://mops.twse.com.tw/mops/web/t164sb04")
getURL(url, curl = curlHandle, .encoding='utf8')
# 送出POST表單(此以抓取台積電(2330), 104年 01季財報為例)
ajax_url = URLencode("http://mops.twse.com.tw/mops/web/ajax_t164sb04")
html = postForm(ajax_url, encodeURIComponent = "1", step = "1", firstin =
"1", off = "1", keyword4 = "", code1 = "", TYPEK2 = "", checkbtn = "",
queryName = "co_id", TYPEK = "all", isnew = "false", co_id = "2330", year =
"104", season = "01", .opts = curlOptions(referer="http://mops.twse.com.tw/mops/web/t164sb04", useragent ="Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/44.0.2403.89 Safari/537.36"), curl = curlHandle, .encoding='utf8')
cat(html, file = "twse.html")
執行總是回復 : in function (type, msg, asError = TRUE) : Empty reply from server
[環境敘述]:
sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950
[2] LC_CTYPE=Chinese (Traditional)_Taiwan.950
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Traditional)_Taiwan.950
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RCurl_1.95-4.7 bitops_1.0-6 XML_3.98-1.3
loaded via a namespace (and not attached):
[1] tools_3.2.1
附上我的header :
https://drive.google.com/open?id=0B_eIxe-HNv0KM0FLRWdMenUxUVU
找了很久總是無法解決, 拜託各位大大指點迷津, 大大感謝 <(_ _)>
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.125.138
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1440179550.A.FD0.html
※ 編輯: justin760204 (140.112.125.138), 08/22/2015 01:56:28
※ 編輯: justin760204 (140.112.125.138), 08/22/2015 01:57:02
※ 編輯: justin760204 (140.112.125.138), 08/22/2015 01:58:23
※ 編輯: justin760204 (140.112.125.138), 08/22/2015 01:59:30
※ 編輯: justin760204 (140.112.125.138), 08/22/2015 02:15:53
※ 編輯: justin760204 (140.112.125.138), 08/22/2015 02:18:00
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章