3

I am trying to get the input type hidden tag values (CAS, AH, 11, etc.) along with the name attribute but all I get is a blank page upon running my PHP based parser. Anybody know what's wrong? I already checked Grabbing hidden inputs as a string (Using PHP Simple HTML DOM Parser) but it was of no help.

Block of html I need to iterate through:

<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">

My solution that displays nothing:

<?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;
    }

}

 ?>
1
  • Try this, foreach($data->find('input[type=hidden]') as $element) echo $element; Commented Sep 7, 2012 at 23:46

1 Answer 1

4

I tried the code and this works for me, I think your $data->find is not correct:

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 />";
    }

}
Sign up to request clarification or add additional context in comments.

1 Comment

Aah, that did work. I guess I was calling the exact xpath when all I needed was to tell it to find hidden input tags. Thank you! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.