quantumdecipher Posted June 22, 2011 Share Posted June 22, 2011 I have a small project, which needs to read a status from an online page. Basically, I need a script to search for a certain tag ID from say www.foo.com/page1.html What I intend to do is get the ID of a certain tag and then save the inner HTML of it into a variable. Any ideas? I tried loading the page in an iFrame and trying JS to get an ID but fails. This is what i tried. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function getContentFromIframe(iFrameName) { var myIFrame = document.getElementById(iFrameName); var content = myIFrame.contentWindow.document.body.innerHTML; var status = content.getElementById('AREA:222_4'); alert(status); } </script> </head> <body> <iframe id="emap" src="http://emaplin3.foo.com/page1.html"> </iframe> <input type="button" value="Get Status" onclick="Javascript: getContentFromIframe('emap')" /> </body> </html> Now I'm lost. Quote Link to comment https://forums.phpfreaks.com/topic/240100-script-to-read-contents-of-website/ Share on other sites More sharing options...
TeNDoLLA Posted June 22, 2011 Share Posted June 22, 2011 Maybe try this. Use file_get_contents() to fetch the page data into a string. Then use DOMDocument to load the HTML string and fetch the data by field ID from the string. http://php.net/manual/en/function.file-get-contents.php http://php.net/manual/en/class.domdocument.php Quote Link to comment https://forums.phpfreaks.com/topic/240100-script-to-read-contents-of-website/#findComment-1233284 Share on other sites More sharing options...
quantumdecipher Posted June 27, 2011 Author Share Posted June 27, 2011 thank you, will definitely try this. I am quit new to this. Quote Link to comment https://forums.phpfreaks.com/topic/240100-script-to-read-contents-of-website/#findComment-1235238 Share on other sites More sharing options...
devWhiz Posted June 27, 2011 Share Posted June 27, 2011 yeah I would use file_get_contents() like so $string = file_get_contents("www.example.com"); echo $string; I'm not familiar with dom so I would just use explode to extract certain content... bad habit there though Quote Link to comment https://forums.phpfreaks.com/topic/240100-script-to-read-contents-of-website/#findComment-1235244 Share on other sites More sharing options...
Nuv Posted June 27, 2011 Share Posted June 27, 2011 Or if you need to POST some value you can use curl(you can do many things with curl though like setting a proxy etc.).However if you don't want to POST values you can use file_get_contents To match the document i use preg_match_all. However, you'll have to learn regex too for that. Quote Link to comment https://forums.phpfreaks.com/topic/240100-script-to-read-contents-of-website/#findComment-1235247 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 27, 2011 Share Posted June 27, 2011 You might want to try learning ajax. Although sometimes, ajax might not be safe. Quote Link to comment https://forums.phpfreaks.com/topic/240100-script-to-read-contents-of-website/#findComment-1235255 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.