php 解析html的工具 嵌入式

PHP Simple HTML Dom Parser使用php5+编写,支持以一种超级简单的方式操纵HTML。 
    * 需要php5以上版本 
    * 支持html标签纠错 
    * 支持jQuery风格选择器 
    * 非常简洁的从HTML中抽取内容 加载整个页面,然后按HTML标记拆成树,然后再通过查找节点,最后读取需要节点的内容文本即可

index.php iframe包含采集页防止采集页js,css等与本站冲突

Java代码   收藏代码
  1. <div class="maincon">   
  2. <iframe id="mainiframe" frameborder=0 width="100%" height="960"  
  3. marginheight=0 marginwidth=0 scrolling=no src="http://localhost/appreciate/mobile/recharge"></iframe>   
  4. </div>  

iframe中修改采集页的form提交action,提交到本站进行处理,将提交的数据在模拟采集页提交。(一个表单做2次提交

http://hudeyong926.iteye.com/blog/903490

Java代码   收藏代码
  1. public function rechargeAction()  
  2. {  
  3.     include_once('lib/simple_html_dom.php');  
  4.     $html = file_get_html(self::RECHARGE_URL);  
  5.     $post_url = $html->find('form'0)->action; //form action  
  6.     $html->getElementById('mobileNo')->outertext = $html->find('input[id=mobileNo]'0)->outertext . "<input type='hidden' name='post_url' value='$post_url'>"//form中传递采集post_url  
  7.     //$html->find('div.more-com',0)->outertext = '';  
  8.     $html->find('form'0)->setAttribute('action''http://localhost/appreciate/mobile/rechargePost'); //修改form action  
  9.     $html->find('td a'1)->setAttribute('href''http://localhost/appreciate/mobile/history'); //修改 订单查询链接  
  10.     $ereg_rule_src_script = '/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/bank\/ddl\/js\/utility\/utility.index.js?/i';  
  11.     foreach ($html->find('script') as $script) {  //正则替换js   
  12.         $script->src = preg_replace($ereg_rule_src_script, 'http://www.test.com/js/lib/dianyin_utility_index.js', $script->src);  
  13.     }  
  14.     $content = $html->save();  
  15.     $html->clear();  
  16.     unset($html);  
  17.     die($content);  
  18. }  

 采集提交后页面

 
 simple_html_dom修改后

Java代码   收藏代码
  1. public function rechargeComfirmPage($post_url, $pdata){  
  2.     include_once("lib/Snoopy.class.php");  
  3.     $snoopy = new Snoopy; //Snoopy post提交  
  4.     $snoopy->fetch(self::RECHARGE_URL); //获取所有内容  
  5.     $snoopy->setcookies();  
  6.     $cookies = $snoopy->cookies;  
  7.     $snoopy->cookies = $cookies;  
  8.   
  9.     $snoopy->submit($post_url, $pdata);//$pdata为提交的数组,$post_url采集提交url  
  10.     return $snoopy->results;  
  11. }  
  12.   
  13. public function rechargePostAction(){  
  14.     $pdata['tranCode']          = $this->getRequest()->getPost('tranCode');  
  15.     $pdata['userCode']          = $this->getRequest()->getPost('userCode');  
  16.     $pdata['runName']           = $this->getRequest()->getPost('runName');  
  17.     $post_url      = $this->getRequest()->getPost('post_url');  
  18.     $this->save2db();  
  19.     $results = $this->rechargeComfirmPage($post_url, $pdata);  
  20.     include_once('lib/simple_html_dom.php');  
  21.     $html = str_get_html($results);//采集提交后页面  
  22.     //修改UI  
  23.     $rate = Mage::helper('recharge/data')->getCurrencyToMoney();  
  24.     $ttt= $this->getLayout()->createBlock('virtualcurrency/customer_accounts_detail')->getCurrentMoney();  
  25.     $html->find('div[id=testPoints]',0)->innertext = $html->find('div[id=testPoints]',0)->innertext*$rate."<input type='button'>";  
  26.     $html->find('div[id=test]',0)->innertext='<table><tr>  
  27.             <td width="30%" align="right"><label class="form-label">您的数:</label></td>  
  28.             <td align="left">  
  29.                 <p class="B Font14 ml10 ">  
  30.                     '.$ttt.'  
  31.                 </p>  
  32.             </td>  
  33.         </tr>  
  34.         <tr>  
  35.             <td width="30%" align="right"><label class="form-label">绑定手机号:</label></td>  
  36.             <td align="left">  
  37.                 <p class="B Font14 ml10 ">  
  38.                     '.$this->_getCustomer()->getMobile().'  
  39.                 </p>  
  40.             </td>  
  41.         </tr></table>';  
  42.   
  43.     die($html);  
  44. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值