Page 1 of 1

Assistance Parsing Multiple links using DOM

Posted: Mon Jan 30, 2012 10:13 pm
by BASiQ
have this code which parses out a div from within the page gotten. Works great.

Code: Select all

$html = file_get_dom('http://steamcommunity.com/profiles/76561198010758659/games?tab=all');
echo $html('div#game_440 h5', 0)->getPlainText();
but I need the code to parse from multiple links, instead of using one link like it does now. I would like these multiple links to be called from a text file.

How would I go about this? I know about the file() function. but I have no idea how to use it. The examples are all wrong

Re: Assistance Parsing Multiple links using DOM

Posted: Tue Jan 31, 2012 5:36 am
by Celauran
What are the file contents like? One such link per line? If so, you could loop through it using fgets() then call your file_get_dom function from within the loop.

Re: Assistance Parsing Multiple links using DOM

Posted: Tue Jan 31, 2012 8:31 am
by BASiQ
After some time, I got this

Code: Select all

        $lines = file('array.htm');
        foreach ($lines as $line) {
        $html = file_get_dom($line);
        echo $html('div#game_440 h5', 0)->getPlainText();
        echo " ";
        echo "$line";
        echo "<br/>";
        } 
but the line

Code: Select all

        echo $html('div#game_440 h5', 0)->getPlainText();
gets me this error when using simple_html_dom.php
"Fatal error: Function name must be a string in /home/MySite/public_html/parse/index.php on line 47"

If I use ganon.php it works fine, but is super slow. Any ideas?

Re: Assistance Parsing Multiple links using DOM

Posted: Tue Jan 31, 2012 10:46 am
by BASiQ
Finished product for reference

Code: Select all

<?php
	include('simple_html_dom.php');
	$lines = file('array.htm');
	foreach ($lines as $line) {
	$html = file_get_dom($line);
	$divline = $html->find('div[id=game_440] h5', 0);
	$divline = preg_replace('/(<h5>)/i', '', $divline); 
	$divline = preg_replace('/(<\/h5>)/i', '', $divline); 
	echo $divline;
	echo " - ";
	echo "$line";
	echo "<br>";
	$html->clear();
	unset($html);
}
array.htm is merely a text file with lines of steam profile links.

Re: Assistance Parsing Multiple links using DOM

Posted: Tue Jan 31, 2012 10:56 am
by BASiQ
Final revised code cleaning up stuff

Code: Select all

<?php
	include('simple_html_dom.php');
	$lines = file('array.htm');
	foreach ($lines as $line) {
	$html = file_get_dom($line);
	$divline = $html->find('div[id=game_440] h5', 0);
	$divline = preg_replace('/(<h5>)/i', '', $divline); 
	$divline = preg_replace('/(<\/h5>)/i', '', $divline); 
	echo $divline." ".$line."<br>";
	$html->clear();
	unset($html);
}
?>