使用以下代码,我们可以获得网页的完整源代码,
<?php
$url1 = "http://adfoc.us/426491";
$ch = curl_init ("$url1");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_REFERER, "http://google.com/");
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0');
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'));
$page = curl_exec ($ch);
echo '<textarea style="width:100%; height: 100%;">' . $page . '</textarea>';
?>
但我的问题是如何从页面获取特定变量,并回显它
例如:
var click_url = "http://somesite.com/serve/click/?id=426491&servehash=af183123696fe5064846368ca7191359×tamp=1337499663";
我是cURL的新手,所以请解释一下 谢谢:))
答案 0 :(得分:0)
您可以使用Dom / Xpath php类来查找和废弃/解析卷曲响应的特定部分。
http://php.net/manual/en/book.dom.php
http://php.net/manual/en/class.domxpath.php
http://iamoso.com/2010/12/24/scraping-sites-using-curl-xpath/