[英]Cheerio not working. What am I doing wrong?
I am trying to scrape a classified ad search result page. 我正在尝试抓取分类广告搜索结果页。
I have tried console logging everything I can to make sure I am getting a response, which I am, but when I actually use cheerio to query something I don't get anything back. 我已经尝试过使用控制台记录所有内容,以确保得到响应,但是实际上当我使用cheerio查询某些内容时,我什么也得不到。 For instance if I just query for how many children using $('.listing-group').children('section').length
I get back 0
instead of 24
when I console log it. 例如,如果我仅使用$('.listing-group').children('section').length
查询多少个子级,则在我进行控制台登录时,它会返回0
而不是24
。
Here is what I'm doing. 这是我在做什么。 Pardon the long URL. 请原谅长URL。
const request = require("request");
const cheerio = require("cheerio");
const app = express();
app.get("/scrape", function(req, res) {
url =
"http://classifieds.ksl.com/search/?keyword=code&category%5B%5D=Books+and+Media&zip=&miles=25&priceFrom=&priceTo=&city=&state=&sort=";
request(url, function(error, response, html) {
if (!error) {
let $ = cheerio.load(html);
let test = $("#search-results").find("section").length
console.log(test);
} else {
console.log("there has been an error");
}
res.send("Check the console.");
});
});
app.listen("8081");
console.log("check localhost:8081/scrape");
exports = module.exports = app;
I'm new to cheerio so I'm assuming I'm probably making a simple error, but with all the tutorials I've checked, I can't seem to find an answer. 我是cheerio的新手,所以我假设我可能正在犯一个简单的错误,但是在检查了所有教程之后,我似乎找不到答案。
Ultimately I want to grab each result on the page (found in the 'section' tags) to display the data for a personal project I'm working on. 最终,我想获取页面上的每个结果(在'section'标签中找到)以显示我正在处理的个人项目的数据。
看起来像:
JSON.parse(html.match(/listings: (\[.*\])/)[1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.