简体   繁体   中英

How to load DIV from external website?

I'm trying to load the ratings, used in this Google website, in my own page. http://www.google.com/maps/place?source=uds&q=restaurants&cid=10470472694367837337

I'd like to show the ratings on my own website, so just loading the ratings-DIV would do the trick.

Any ideas?

You could use PHP (or another backend language) to crawl that page, extracting the div, then pass it to the website.

However, seeing how the ratings come from google, I'd suggest you take a look if there isn't some google API you can use to get the ratings. I don't know what API you can use from mind but this should help you out with that.

http://code.google.com/intl/nl-NL/more/table/

Get the page and parse it. For PHP you could use http://www.phpclasses.org/package/3086-PHP-Parse-and-extract-information-from-HTML-using-SQL.html to parse it in a SQL style.

You shouls use the places api google provide. Its a webservice that returns information on places and locations. You will need a google account and to setup a api key which you can do here

You can then call this api from client or server side code. The place details results of the place Details api call returns a rating.

You should not just extract html content from another sites webpage!

You can use PHP Simple HTML DOM Parser http://simplehtmldom.sourceforge.net/

$html = file_get_html('http://www.google.com/maps/place?source=uds&q=restaurants&cid=10470472694367837337');
foreach ($html -> find('div.rsw-stars') as $element)
    print count($element -> find('.rsw-starred')) . '<br>';

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM