PHP DOM节点采集

https://github.com/owner888/phpspider

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

<div class="maincon"> 
<iframe id="mainiframe" frameborder=0 width="100%" height="960"
marginheight=0 marginwidth=0 scrolling=no src="http://localhost/appreciate/mobile/recharge"></iframe> 
</div>

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

public function rechargeAction()
{
    include_once('lib/simple_html_dom.php');
    $html = file_get_html(self::RECHARGE_URL);
    $post_url = $html->find('form', 0)->action; //form action
    $html->getElementById('mobileNo')->outertext = $html->find('input[id=mobileNo]', 0)->outertext . "<input type='hidden' name='post_url' value='$post_url'>"; //form中传递采集post_url
    //$html->find('div.more-com',0)->outertext = '';
    $html->find('form', 0)->setAttribute('action', 'http://localhost/appreciate/mobile/rechargePost'); //修改form action
    $html->find('td a', 1)->setAttribute('href', 'http://localhost/appreciate/mobile/history'); //修改 订单查询链接
    $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';
    foreach ($html->find('script') as $script) {  //正则替换js 
        $script->src = preg_replace($ereg_rule_src_script, 'http://www.test.com/js/lib/dianyin_utility_index.js', $script->src);
    }
    $content = $html->save();
    $html->clear();
    unset($html);
    die($content);
}

 采集提交后页面

 
 simple_html_dom修改后

public function rechargeComfirmPage($post_url, $pdata){
	include_once("lib/Snoopy.class.php");
	$snoopy = new Snoopy; //Snoopy post提交
	$snoopy->fetch(self::RECHARGE_URL); //获取所有内容
	$snoopy->setcookies();
	$cookies = $snoopy->cookies;
	$snoopy->cookies = $cookies;

	$snoopy->submit($post_url, $pdata);//$pdata为提交的数组,$post_url采集提交url
	return $snoopy->results;
}

public function rechargePostAction(){
	$pdata['tranCode'] 			= $this->getRequest()->getPost('tranCode');
	$pdata['userCode']       	= $this->getRequest()->getPost('userCode');
	$pdata['runName']    		= $this->getRequest()->getPost('runName');
	$post_url      = $this->getRequest()->getPost('post_url');
	$this->save2db();
	$results = $this->rechargeComfirmPage($post_url, $pdata);
	include_once('lib/simple_html_dom.php');
	$html = str_get_html($results);//采集提交后页面
	//修改UI
	$rate = Mage::helper('recharge/data')->getCurrencyToMoney();
	$ttt= $this->getLayout()->createBlock('virtualcurrency/customer_accounts_detail')->getCurrentMoney();
	$html->find('div[id=testPoints]',0)->innertext = $html->find('div[id=testPoints]',0)->innertext*$rate."<input type='button'>";
	$html->find('div[id=test]',0)->innertext='<table><tr>
			<td width="30%" align="right"><label class="form-label">您的数:</label></td>
			<td align="left">
				<p class="B Font14 ml10 ">
					'.$ttt.'
				</p>
			</td>
		</tr>
		<tr>
			<td width="30%" align="right"><label class="form-label">绑定手机号:</label></td>
			<td align="left">
				<p class="B Font14 ml10 ">
					'.$this->_getCustomer()->getMobile().'
				</p>
			</td>
		</tr></table>';

	die($html);
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值