每次尝试使用YQL刮擦Web内容时,都会取得无效



嗨,我正在使用YQL从外部网站获取Web内容。但是,尽管使用了适当的XPATH值和JOSON,但我总是以null的形式获得结果。谁能帮我解决这个问题?我正在尝试在下面的网站上获取内容。如果YQL有任何问题,谁能建议我替代YQL?我已经尝试过了。请看一下。

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? concoding = utf8& ref = cm_sw_wa_wa_apa_apa_apa_apa_apa_i_i_5c5c5c5c5c5uzbqg5aa293

这是一个完整的示例,但首先您需要:

  • 使用https(http可能会返回null或错误(。
  • 请记住,您正在获得元标记,因此,如果您需要或尝试在HTML中显示结果,您什么也看不到,因此我使用控制台。

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>

相关内容

最新更新