嗨,我正在使用yql从外部网站获取网页内容。但是,尽管使用了正确的xpath值和foramt作为json,我总是得到结果为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);
})
答案 0 :(得分:0)
以下是完整的示例,但首先您需要:
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>