3

我正在尝试获取输入类型隐藏标记值(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;
    }

}

 ?>
4

1 回答 1

4

我尝试了代码,这对我有用,我认为您的 $data->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 />";
    }

}
于 2012-09-07T23:54:47.207 回答