Ash3r Posted March 25, 2010 Share Posted March 25, 2010 Let me first start by saying thank you for clicking on this thread, reading, and potentially providing good feedback. I really need YOUR help Here is the issue/problem that i have encountered ... I AM CRAP @ PHP ! 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. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/ Share on other sites More sharing options...
JustLikeIcarus Posted March 25, 2010 Share Posted March 25, 2010 I would recommend either finding an RSS feed containing the data you want or possibly looking into using Yahoo Query Language which is geared towards this type of thing. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031509 Share on other sites More sharing options...
Ash3r Posted March 25, 2010 Author Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031511 Share on other sites More sharing options...
JustLikeIcarus Posted March 25, 2010 Share Posted March 25, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031514 Share on other sites More sharing options...
oni-kun Posted March 25, 2010 Share Posted March 25, 2010 If you're not in to regex (As I assume you're not wanting to do it) you can retrieve the div easily with the HTML DOM class. EDIT: I'd recommend against CURL unless you need to send headers, such as POST data. file_get_contents should suffice Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031516 Share on other sites More sharing options...
JustLikeIcarus Posted March 25, 2010 Share Posted March 25, 2010 Have you looked into using Weather.com's xmloap developer feed http://www.weather.com/services/xmloap.html. API keys are free you just need to sign up. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031517 Share on other sites More sharing options...
JustLikeIcarus Posted March 25, 2010 Share Posted March 25, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031520 Share on other sites More sharing options...
oni-kun Posted March 25, 2010 Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031525 Share on other sites More sharing options...
JustLikeIcarus Posted March 25, 2010 Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031527 Share on other sites More sharing options...
Ash3r Posted March 25, 2010 Author Share Posted March 25, 2010 @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... Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031538 Share on other sites More sharing options...
oni-kun Posted March 25, 2010 Share Posted March 25, 2010 @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 Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031573 Share on other sites More sharing options...
Ash3r Posted March 25, 2010 Author Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031745 Share on other sites More sharing options...
oni-kun Posted March 25, 2010 Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196451-help-want-to-display-another-sites-content-on-my-site-using-a-get-code/#findComment-1031875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.