Hi all, can someone help me get the content of a div in a web site in another domain?
Im a little lost with this.
thanks

Recommended Answers

All 4 Replies

==IGNORE==
Well this is what I would do.

$file = file_get_contents("http://website.com/thepage");
$div = preg_match('#<div id="id">(.*)</div>#',$file);
echo $div;

With a regular expression it's quite simple. That should work, if not sorry it's my best guess.

==SORRY==
OH I'm sorry, I saw this on the homepage and just realised this is ASP not php...

i program in asp but i can use php also, could you give a more complete example?
thanks

There was a recent thread that I commented on which was similar to what you are trying to accomplish but I wasnt able to easily locate it. In any event, there are different methods you can use to accomplish the same result.

One alternative is to use an iframe element on your page and load the content from the other page using jQuery. I have an example that you are free to use that can be easily modified to load display only the contents from a div located on the target page.

Display a GIF During IFRAME Loading [jQuery]

In the example/demo, a "loading" animated GIF is displayed until the content is loaded into the iframe. That's good, but in your question you want to display only the contents from a target div.

The example could be modified as follows:

<iframe id="iframe1" src="targetPage.html#divID" scrolling="no" ></iframe>

If you know the expected size of the target div, you can style your iframe so that the width and heights match and since scrolling is set to "no", the contents should fit nicely in the iframe element.

Hi, thanks i see some potencial althought i only need to get the text.

Im builder a store bot to get products for resellers. i only need the text.

thanks
obrigado

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.