php - Unsure on how to convert the code I already have to html dom -
the scraping code have not working i've searched , found need use dom , unsure how implement have dom after reading. worried breaking something. help/tutorials highly appreciated.
// input $link = post('link1'); $category = post('category'); $time = post('time'); // markers $findme1 = 'https://www.mturk.com/mturk/preview?groupid='; $findme2 = '<span class="reward">'; $findme3 = '</span>'; // check if link correct $rightlink = strpos($link, $findme1); // if link correct if ($rightlink !== false) { // html link $html = file($link); // iterate through html foreach ($html $i => $line) { // set title if($i == 640) $title = htmlentities($line); // set requester if($i==669) $requester = htmlentities($line); if($i==678) { // modify line , save reward $line_modified = str_replace($findme2, '', $line); $line_modified = str_replace($findme3, '', $line_modified); $reward = htmlentities($line_modified); } // set qualifications if($i==711) $q = htmlentities($line); }
try php simple html dom parser, it'll make life easy, read documentation , whatever want do. if familiar jquery it's in grip. @ example given below
include('simple_html_dom.php'); $html = file_get_html('https://requester.mturk.com/'); foreach($html->find('a') $link){ echo $link . '<br />'; } that code fetches data https://requester.mturk.com , prints links using foreach loop. code self descriptive think.
Comments
Post a Comment