I wish to 'steal' a div of a web site and embed it on my site (without using iframe). Can anyone tell me what is the exact way to do that? Thanks.
Pretty Simple:
You can use file_get_contents() or http://simplehtmldom.sourceforge.net/manual.htm to get the page as all the HTML and then get the DIV using javascript or Jquery.
An example would be:
$homepage = file_get_contents('http://www.somesite.com/');
Then you can parse the $homepage variable.
OR
What I would do is:
http://simplehtmldom.sourceforge.net/manual.htm
$html = file_get_html('http://www.google.com/');
$ret = $html->find('div[id=foo]');
As an addition to @jini's answer , you could make that script into a file, gate.php
, and load things using only jQuery:
$('#container').load('gateway.php?url=foo.com #target_div');
And a possible gateway.php
:
<?php
print file_get_contents($_GET['url']);
?>
Just make sure to sanitize your input!
you can use yahoo yql with data scraping, exactly made for these purpose.
http://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_html_scraper
you can use Xpath
ex
select * from html where url="http://finance.yahoo.com/q?s={ticker_sym}" and xpath='//div[@id="yfi_headlines"]/div[2]/ul/li/a'
Yahoo pipes is a good place to start using the 'fetch page' module. After that it'a a case of rubbing or changing out the html that you don't want with the regex module.
Embedding can be done in two ways:
2.Yahoo pipes have a module that will POST data (in JSON format) to a suitable input processing page that will store the information for inclusion in any page that requires the data.
A brilliant (and wholly legal) example of this action can be seen over at http://bishop.comxa.com
Ask nicely they may even give you some pointers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.