Jump to content

Website Parsing


Natefons

Recommended Posts

background

im trying to design a page that uses data from another website (lets say http://example.com)

the said website doesnt have any sort of API, but they do output all there data to the Source. (view->source)

 

 

Question:

soo im wondering, what would be the ideal method to parse data from this website and get the data values i need?

 

i know, File_get_contents(URL) will grab the source from said url, but now how can i  grab that data?

 

suppose file_get_contents grabs this:

<title>this is my title</title>
<body>
blah blah blah
<li class="points">
<span>Points</span>
<strong>2370</strong>
</li>		
</body>

 

now i want to display the number of points on MY page..how can i go about?

 

 

 

 

--hope i was clear enough

 

Nate

Link to comment
Share on other sites

<?php

//Here we use file_get_contents to get the page without executing it yet
$content = file_get_contents('http://www.website.com/page.php');

//Then we grab the first html tag
$temp = explode('<strong>',$content);

//Next we grab the end html tag

$temp2 = explode('</strong>',$temp[1]);

//Then we grab the points which is contained within the above tags

$points = $temp2[0];

//Then we combine all the variables

unset($content,$temp,$temp2);

// Now we are done and display it  

print_r($points);

?>

Link to comment
Share on other sites

phpnewb's example will only work if AND ONLY IF the format of the page is exactly the same of your example. What if there are strong tags before the points value? what if there are <b> tags?

 

madtechies is better, but it also assumes that there is <strong>points</strong>

 

are you sure that the format for the page(s) will have <strong>points</strong>. could it be different? if not i suggest using madtechies example, but if so, then more info is needed

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.