Jump to content

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.

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.