【发布时间】:2018-11-11 00:39:33
【问题描述】:
网址 = http://www.simon.com/mall/anchorage-5th-avenue-mall/stores
上面的网址列出了特定商场中的所有商店。我想要做的是从该链接中抓取该链接以获取该商场中所有商店的列表。这是我到目前为止的代码
request(url, function(err, resp, body) {
if (err) {
console.log(err);
} else {
var $ = cheerio.load(body);
$('h2.card-secondary-title.name.copy').each(function() {
var text = $(this).text();
console.log(text);
});
}
})
此格式的网页在哪里
<html>
<head>
<main id="simon" class>
<section class="directory">
<div id="root">
...
<div class="directory-grid row">
...
<h2 class="card-secondary-title name copy">5th Avenue Deli</h2>
我什至无法从网站上抓取任何一家商店。使用这种方法,我已经能够从许多其他网站上刮下来,但由于某种原因,这个无法正常工作
【问题讨论】:
-
可能是因为在您获得第一个答案后加载商店列表需要一些时间(它已加载 ajax),因此您可能需要在迭代之前检查特定组件...跨度>
标签: javascript html node.js web-scraping cheerio