简体   繁体   English

如何从请求主体获得结果

[英]How to get the result from request body

I use Node js 我使用Node js

Using cheerio library, I try to parse a page. 使用cheerio库,我尝试解析一个页面。

By request, I got body of a webpage. 应要求,我得到了网页的正文。

In this body, I want to get contents of 在这个身体中,我想获得

Below is my code : 下面是我的代码:

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);
});

The result of 'console.log(body)' is 'XML'. “ console.log(body)”的结果为“ XML”。 And I want to get contents of 我想获取的内容

And Can I convert it to JSON?? 我可以将其转换为JSON吗?

根据Yahoo的文档 ,您只需要添加format=json查询字符串参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM