作者microtech (microtech)
看板PHP
标题Re: [请益] 使用simple_html_dom parsing aspx的网站
时间Wed Jul 10 15:51:54 2013
※ 引述《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