Jump to content

Script to Read Contents of Website


quantumdecipher

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/240100-script-to-read-contents-of-website/
Share on other sites

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

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.