[英]How to get the result from request body
我使用Node js
使用cheerio庫,我嘗試解析一個頁面。
應要求,我得到了網頁的正文。
在這個身體中,我想獲得
下面是我的代碼:
var cheerio = require('cheerio');
var request = require('request');
request('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Ffortune.daum.net%2Fexternal%2F4%2Frun%2Fstar_free%2Findex.php%22%20and%0A%20%20%20%20%20%20xpath%3D%27%2F%2Ftd%5Bcontains(%40style%2C%22font-family%3A%EA%B5%B4%EB%A6%BC%3B%20font-size%3A12px%3B%20color%3A%23333333%3B%20line-height%3A18px%3B%20padding-right%3A10px%22)%5D%27&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys',
function(error,response,body){
console.log(body);
//var info =JSON.parse(body);
});
“ console.log(body)”的結果為“ XML”。 我想獲取的內容
我可以將其轉換為JSON嗎?
根據Yahoo的文檔 ,您只需要添加format=json
查詢字符串參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.