simplehtmldom奇怪的行为

时间:2012-11-22 15:02:57

标签: php curl simple-html-dom

我遇到了一些奇怪的simplehtmldom行为。

我从某个页面获取$newlink,然后将其放入另一个卷曲中,返回空白数据。如果我改变

curl_setopt($ch1, CURLOPT_URL, $newlink);

curl_setopt($ch1, CURLOPT_URL, "http://www.granma.cu/italiano/sport/22-noviembre-iaaf.html");

正在显示数据。哪里是我的错误?

<?php header("Content-Type: text/html; charset=utf-8"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
require dirname(__FILE__) . '/simple_html_dom.php'; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://youlichika.netii.net/aaa.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$htmls = curl_exec($ch);
curl_close($ch);
$html = str_get_html($htmls);
$newlink = $html->find('p',0);
echo $newlink;
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $newlink);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$newhtml = curl_exec($ch1);
curl_close($ch1);
echo $newhtml;
?>

1 个答案:

答案 0 :(得分:0)

您需要使用$newlink->innertext来获取<p>代码之间的内容。