Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get hidden input tag value as string using PHP simple HTML DOM

Tags:

html

dom

php

hidden

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

}

 ?>
like image 682
wandersolo Avatar asked Dec 13 '25 12:12

wandersolo


1 Answers

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

}
like image 176
raygo Avatar answered Dec 15 '25 01:12

raygo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!