Re: [請益] 使用simple_html_dom parsing aspx的網站
※ 引述《ireullin (raison detre)》之銘言:
: 請問一下
: 我使用 simple_html_dom 去抓取一個aspx網站的內容
: 作法如下
: $data=array(
: '__EVENTTARGET'=>'',
: '__EVENTARGUMENT'=>'',
: '__LASTFOCUS'=>'',
: '__VIEWSTATE'=>'',
: '__EVENTVALIDATION'=>'',
: );
: $data_url = http_build_query($data);
: $data_len = strlen ($data_url);
: $request = array(
: 'http' => array (
: 'method' => 'POST',
: 'content' => $data_url,
: 'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
: "Content-Length: " . $data_len . "\r\n"
: )
: );
: $context = stream_context_create($request);
: $html = file_get_html(
: 'http://www.url.com.tw/history.aspx',
: false,
: $context
: );
: 可是以下這幾個欄位
: __EVENTTARGET
: __EVENTARGUMENT
: __LASTFOCUS
: __VIEWSTATE
: __EVENTVALIDATION
: 不知道要填什麼
: 因為他是一連串不明的編碼
: 可是如果保持空白
: 或是填入與 fiddler中看到相同的值的話
: 抓到的都是此網頁不存在
: 請問針對aspx的這種網頁
: 該如何去parsing
如果是單純抓這網址(http://www.taiwanlottery.com.tw/Lotto/SuperLotto638/history.aspx)
可以不需要post那些欄位
但是用Charles觀察發現單純抓的時候會多返回一個404的網址(如圖http://i.imgur.com/XtS6JFx.png)
http://www.taiwanlottery.com.tw/Lotto/SuperLotto638/*.html
也許你抓到的都是最後一個返回的404的網址
如果是要查詢特定年/月,post的欄位如下圖所示:
http://i.imgur.com/F8CKOeM.png
雖然工作主要是使用php,不過以前習慣用java
所以工作上的需求還是用java來完成
最近才去搜尋php相關的html parser套件,因此在板上看到這篇問題就很有興趣了
你可以找看看為什麼Simple HTML DOM Parser會抓到404的網址
對了,在查詢特定年/月時,__VIEWSTATE/__EVENTVALIDATION需要使用它給的值
不然會抓到重導回查詢頁的資訊
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.209.20.204
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 5 篇):