【发布时间】:2014-04-29 17:43:46
【问题描述】:
好的,所以我已经为此奋斗了一段时间,所以也许有人可以帮助我。
我正在尝试从此 HTML 获取电子邮件链接:
<div id="field_11" class="fieldRow span12 lastFieldRow">
<span class="caption">E-mail</span>
<span class="output">
<script type="text/javascript">
<!--
document.write('<a hr'+'ef="mai'+'lto'+':'+
'%40;%67;%6d;%61;%69;%6c;<\/a>');
//-->
</script>
<a href="mailto:%40%67%6d%61%69%6c">@mail</a>
</span>
</div>
我试图在 a href="mailto:..." 部分之后获取 html 代码的“@mail”部分。不是 document.write() 部分,而是代码中的最后一个标签。
出于某种原因,当我尝试使用输出类获取标签跨度的子级时,它认为它只有 1 个子级,即脚本标签,但我似乎无法获取电子邮件纯文本。
到目前为止我有什么:
$target_url = "some_web_site";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('span[class=output]') as $d){
echo $d->children(1)->plaintext . "<br />";
}
有什么帮助吗?
【问题讨论】:
-
您的代码应该可以工作,它的输出是什么(或错误消息)?
-
它会打印出一堆这样的错误:注意:尝试在第 224 行的 /Applications/MAMP/htdocs/webcrawler/index.php 中获取非对象的属性
-
听起来您的
load_file()加载不正确。您可以尝试删除第 2 行和第 3 行(均以$html开头,并替换为$html = file_get_html($target_url);? -
@LaughDonor - 尝试了你的方法,仍然有这些错误。
-
嗯,您遇到此问题的主要原因是
$html->find('span[class=output]')正在返回null。您需要检查以确保您的选择器是正确的。也许改用span.output?