1

Please be aware my experience with coding is pretty much just CSS/HTML. I was also recently introduced to jQuery. But I am very willing to try out your solutions (if my skills permit).

So what I want to do is include the reviews from this site here: Airbnb - Mailodging. Using Firefox's Inspect tool, I found that you can locate the div for just the reviews with this class:

div.panel.reviews.space2

I've tried searching for a way to include a specific class (not an ID#) from an external page using iframes, but seems it's impossible. Is there a workaround or any other solution you can suggest?

At the moment the only way I found to include the reviews is through a hideous iframe. It displays the entire page, which I don't want. You can see it here. Yuck! Seems I'm better off just opening the Airbnb page through a new tab.

Amanda Nguyen
  • 35
  • 1
  • 4
  • You can use `jQuery.load()` to pull in a specific section of a remote webpage and put it anywhere on your webpage. If the section you need doesn't have an ID, you'll have to crawl the page with a scripting language like PHP to grab the content you need. – Nick Pickering Mar 10 '13 at 22:02
  • 1
    @NicholasPickering The `load()` call would violate the [same-origin-policy](https://developer.mozilla.org/en-US/docs/JavaScript/Same_origin_policy_for_JavaScript) – Boaz Mar 10 '13 at 22:08
  • There's an [unofficial Airbnb API](https://www.mashape.com/john-matt/airbnb) in the making. But it's not working yet. – Boaz Mar 10 '13 at 22:19
  • Your best bet is to redirect users to your airbnb profile at the moment. – Nick Pickering Mar 11 '13 at 05:31
  • Thanks everyone. I just decided to quote some of the reviews off of Airbnb and link to the page. – Amanda Nguyen Mar 12 '13 at 04:01

2 Answers2

0

Use jquery.load() or jquery.ajax to load your external html page into your current page. And within the callback function for each method, you can set, reference or modify your css selector that's on your external page, any way you want. You just gotta read up on the API on how to use it properly. Good Luck!

klewis
  • 7,459
  • 15
  • 58
  • 102
  • 1
    This would violate the [same-origin-policy](https://developer.mozilla.org/en-US/docs/JavaScript/Same_origin_policy_for_JavaScript) – Boaz Mar 10 '13 at 22:08
  • ohh, the external content is not on the same domain? then call it into your current page using an iframe. but can you edit the external data yourself? or not? That is the big question. – klewis Mar 10 '13 at 22:09
  • Airbnb is a large commercial site from which the OP is looking to scrape their personal profile page - so no :) – Boaz Mar 10 '13 at 22:11
  • ok, the only thing I can suggest is using jquery's contents() approach - read this up and give it a shot! - http://stackoverflow.com/questions/5924936/change-html-of-an-iframe-with-jquery but that may not work unless that external page is also on your same domain. but it doesn't hurt to try. – klewis Mar 10 '13 at 22:13
0

I would agree with Nicholas, reviewing your site, and the .load() documentation the code could go something a little like this:

$('body.en').load('https://www.airbnb.ca/users/show/9187 div.reviews_section as_host');

Untested, so not sure if that will work 100% given that it's a remote site your retrieving from and not sure if this function was designed for that purpose, but give it a try.

Jester
  • 399
  • 2
  • 3
  • 15