Jump to content

Recommended Posts

Hi Guys,

 

i was curious as to how i could go about reading parts of another webbsite, say i type a website url in and click submit the script would goto that page and read certain pieces of information i told it to kinda thing

 

what would be the best way to go abput it, i have just mastered xml files you need to load them in first before you can grab the relevant data but not sure how i would go about doing the same for webpages

 

any advice would be great

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/67670-how-to-read-another-website/
Share on other sites

If you want to do fancy things like cookies and sending POST data, you'll probably want to look at CURL.

 

For just a basic webpage read, all of the fopen functions will work just as if it was a file on the local drive.

 

<?php
echo file_get_contents("http://www.google.com");

I grab parts of a weather page to display on my site and Reg Ex is the key. My finished code is in the bottom post on this page:

http://www.phpfreaks.com/forums/index.php/topic,120594.msg494739.html#msg494739

 

It should give you an idea of what needs to be done.

Hi Guys,

 

it's really for getting the rating from imdn of a movie , for a review site

 

code:

 

<?php
//=====================================================================================//
// IMDB get rating...
//=====================================================================================//

$str_text = file_get_contents("http://www.imdb.com/title/tt0373883/"); 

$pattern = '/(h1|src)=[\'"]/'; 

preg_match_all($pattern, $str_text, $matches); 

echo "<pre>"; 
var_dump($matches); 
echo "</pre>"; 
?>

 

im not to sure how to set up the reg ex for the rating which is incased in this code:

 

</div>
<div class="general rating">
<div class="starbar static"><div class="outer"><div class="inner" style="width: 64px"></div></div></div>
<b>User Rating:</b> 
<b>3.2/10</b> 
  <small>(<a href="ratings">323 votes</a>)</small>
<div class="bottom">

 

the 3.2/10 is the only bit im really after , any help on the reg ex code would be appreciated

 

thanks guys

 

Graham

 

 

That should be easy for someone who understands RegEx.  The thing that trips me up is the fact that the part you need to match is spread over two lines.

<b>User Rating:</b>

<b>3.2/10</b>

I hope someone solves this because I would like to see how it is done.

 

 

 

 

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.