0

Hi, I'm using yql to fetch web content from an external website. But, despite of using proper xpath value and foramt as json too, I'm always getting result as null. Can anyone help me out to sort this? I'm trying to get content for this below website. If yql has any prob, can anyone suggest me some alternative to yql? I have tried this so far. Please have a look at it.

var site = "http://www.amazon.in/Seiko-Premier-Analog-Blue-Watch/dp/B012T413GO?_encoding=UTF8&ref_=cm_sw_r_wa_apa_i_5c5uzbQG5A293";
site = site.replace('m.', '')
var yql = "SELECT * FROM html WHERE url='" + site + "' AND xpath='//title|//head/meta'";
var resturl = "http://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(yql) + "&format=json";

$.getJSON(resturl,function(data){
    console.log(data);
})

http://www.amazon.in/Seiko-Premier-Analog-Blue-Watch/dp/B012T413GO?encoding=UTF8&ref=cm_sw_r_wa_apa_i_5c5uzbQG5A293

1 Answers1

0

Here is the complete example, but first you need to:

  • Use https (http will likely return null or error).
  • Remember that you're getting meta tags, so if you need or try to show the results in HTML, you'll see nothing, hence I use the console.

var site = "https://www.amazon.in/Seiko-Premier-Analog-Blue-Watch/dp/B012T413GO?encoding=UTF8&ref=cm_sw_r_wa_apa_i_5c5uzbQG5A293";
site = site.replace('m.', '');

var yql = "select * from htmlstring where url='" + site + "' AND xpath='//title|//head/meta'";

var resturl = "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(yql) + "&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback=";

$.getJSON(resturl, function(data) {
  console.log(data.query.results.result);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<div id="divContent"><i>Look the console - the results are not visible (they're only meta tags):</i></div>
Mauricio Arias Olave
  • 2,259
  • 4
  • 25
  • 70
  • I need given url's Meta description, title and image (ex: if amazon link, then product image). Can you please help me out with this? I'm new to yql. So dont have much idea on this. –  Jun 30 '17 at 05:45
  • @Sinchan, with my answer, now you can get those information. According to your profile, you know about javascript, jquery and so on. Did you try "again, with the results of my answer" get the information you need? = did you try anything else? if so, [edit] your question – Mauricio Arias Olave Jun 30 '17 at 13:20
  • I hope you have seen another question too which you replied as well. I changed that question. Here is the link to that question: https://stackoverflow.com/questions/44804635/unable-to-scrape-image-meta-description-and-title-from-an-url-content-using-yql?noredirect=1#comment76648117_44804635 –  Jul 03 '17 at 05:52