我正在尝试获取输入类型隐藏标记值(CAS,AH,11等)以及name属性,但在运行基于PHP的解析器时,我得到的只是一个空白页面。谁知道什么是错的?我已经检查了Grabbing hidden inputs as a string (Using PHP Simple HTML DOM Parser),但没有任何帮助。
阻止html我需要迭代:
<td valign="bottom" align="center">
<input type="hidden" value="CAS" name="College">
<input type="hidden" value="AH" name="Dept">
<input type="hidden" value="111" name="Course">
<input type="hidden" value="J1" name="Section">
<input type="hidden" value="" name="Subject">
<input type="hidden" value="" name="MtgDay">
<input type="hidden" value="" name="MtgTime">
我的解决方案没有显示任何内容:
<?php
include('simple_html_dom.php');
$seed = 'https://www.bu.edu/link/bin/uiscgi_studentlink.pl/1346752597?ModuleName=univschr.pl&SearchOptionDesc=Class+Subject&SearchOptionCd=C&KeySem=20133&ViewSem=Fall+2012&Subject=&MtgDay=&MtgTime=';
web_scrape($seed);
function web_scrape($url)
{
$data = new simple_html_dom();
$data->load_file($url);
$nodes = $data->find("/html/body/form/center/table/tbody/tr/td[2]/input[type=hidden]");
foreach ($nodes as $node) {
$val = $node->value;
echo $val;
}
}
?>
答案 0 :(得分:4)
我尝试了代码,这对我有用,我认为你的$ data-&gt; find不正确:
include('../simple_html_dom.php');
$seed = 'https://www.bu.edu/link/bin/uiscgi_studentlink.pl/1346752597?ModuleName=univschr.pl&SearchOptionDesc=Class+Subject&SearchOptionCd=C&KeySem=20133&ViewSem=Fall+2012&Subject=&MtgDay=&MtgTime=';
web_scrape($seed);
function web_scrape($url)
{
$data = file_get_html($url);
//$data = new simple_html_dom();
// $data->load_file($url);
$nodes = $data->find("input[type=hidden]");
foreach ($nodes as $node) {
$val = $node->value;
echo $val . "<br />";
}
}