Jump to content

HELP ! ... want to display another site's content on my site. (using a get code)


Ash3r

Recommended Posts

Let me first start by saying thank you for clicking on this thread, reading, and potentially providing good feedback.

I really need YOUR help :D

 

Here is the issue/problem that i have encountered ... I AM CRAP @ PHP !  :shrug:

 

I am trying to create a simple PHP code that will take the data from another site's "<div class>" field and display it on mine. (say something like weather.com)

If you use google chrome ... it has a great little tool called "inspect element" which opens a sort of debug screen that allows you to see the HTML code in a special pop-up

 

Here is an example of what I am trying to do ... (in case I have not explained myself clearly enough)

If you go to weather.com and right-click the "STORM WATCH" text and inspect element (in Google Chrome or view page in an HTML viewer).

You will see the class is called <p class="hpNCHeader"> ... I want to pull the contents of that container and echo it (i think this is the term) on my own webpage. (ultimately the end result down the line is that I am wanting to create an e107 plugin.)

 

Please let me know if you need anymore information on what I am looking for ... also WEATHER.COM is only an example (so, please do not post replies telling me about other weather related plugins or codes ... I was just trying to use a site that everybody was somewhat familiar with.)

 

Thank you in advance and I look forward to your reply.

 

Link to comment
Share on other sites

There is no RSS feed for the information that I want to pull from a particular site... Took a look at the YQL, and it doesn't seem like it is the solution for me.

 

I am looking really for an example of code I can use, not where or what I need to do ... but thank you for the suggestions.

Link to comment
Share on other sites

You can try pulling the contents of the page into a variable using php/curl

 

<? 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec();
curl_close($ch);
?>

Link to comment
Share on other sites

Also keep in mind that if you scrape content from a site without using an api provided by them for that purpose then you are essentially stealing their content.  They can get upset about this since it bypasses advertising etc...

 

Content is public. There's nothing in the terms of service that involve scraping.

Link to comment
Share on other sites

Content is public. There's nothing in the terms of service that involve scraping.

 

It is public to a point.  It is still property of weather.com in this case.  They have advertisers paying them because people go to the sight to view that information.  If you pull the data off of there site to display on another site then you are bypassing those advertisements.  This is why sites like weather.com introduce api's for pulling their information from the backend directly.  You agree to a specific terms of service for use of that interface.

Link to comment
Share on other sites

@oni-kun

how do i take the following and a pull a specific div-class element ?

// Create DOM from URL or file

$html = file_get_html('http://www.google.com/');

 

// Find all images

foreach($html->find('img') as $element)

      echo $element->src . '<br>';

 

// Find all links

foreach($html->find('a') as $element)

      echo $element->href . '<br>';

@JustlikeIcarus

Please let me know if you need anymore information on what I am looking for ... also WEATHER.COM is only an example (so, please do not post replies telling me about other weather related plugins or codes ... I was just trying to use a site that everybody was somewhat familiar with.)

 

Please see original post...

Link to comment
Share on other sites

@oni-kun

how do i take the following and a pull a specific div-class element ?

 

I believe it is simple as this:

$html = file_get_html('http://www.whateversite.com/');
$ret = $html->find('div[.foo]'); 

 

Of course '.foo' would be replaced with the class of the div you wish to pull, There are more examples in this manual:

 

http://simplehtmldom.sourceforge.net/manual.htm

Link to comment
Share on other sites

I seem to be getting a PHP error with the following ... here is the page online I am trying to load with error on line 16 http://www.lncgaming.com/TEST/stats_test.php

 

And here is the code that i used ...

Line 16 : $html->load_file('http://www.weather.com/');

Line 17 : $ret = $html->find('div[class=hpNCHeader]');

Also I am trying to figure out the echo code that will allow me to echo the value in that div class on that page.

 

I am sorry to be a pain and I know I am probably over my head with this.

Link to comment
Share on other sites

I seem to be getting a PHP error with the following ... here is the page online I am trying to load with error on line 16 http://www.lncgaming.com/TEST/stats_test.php

 

And here is the code that i used ...

Line 16 : $html->load_file('http://www.weather.com/');

Line 17 : $ret = $html->find('div[class=hpNCHeader]');

Also I am trying to figure out the echo code that will allow me to echo the value in that div class on that page.

 

I am sorry to be a pain and I know I am probably over my head with this.

 

Why are you not using file_get_html()? Load_file doesn't create an object.

I believe:

$ret = $html->find('div[class=hpNCHeader]')->innerhtml;

Should work, but it shows that in the manual.

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.