我正试图从NodeJS & Cheerio网站上搜索一些文本。我尝试了很多在互联网上找到的解决方案,但是我的结果总是空洞的。
我想要废除的网站:https://www.bodybuilding.com/exercises/dumbbell-bench-press
相关HTML代码:
<div class="ExDetail" itemscope itemtype="http://schema.org/ExerciseAction">
<section class="ExDetail-section ExDetail-meta flexo-container flexo-start flexo-between">
<div class="grid-8 grid-12-s grid-12-m">
<h2 class="ExHeading ExHeading--h2 ExDetail-h2" itemprop="name">
Dumbbell Bench Press
</h2>
</div>我在试着弄到这篇文章:哑铃板凳出版社
但我已经尽我所能..。
我现在的代码是:
request(url, function(error, response, html) {
if (!error) {
var $ = cheerio.load(html);
var name = $('h2.ExHeading.ExHeading--h2.ExDetail-h2').text();
console.log(name);
var json = {
name: name
};
res.send(json);
}
});编辑:添加了我想要删除的链接。
发布于 2018-05-27 10:04:48
答:在标题中添加一个假用户代理解决了问题!
https://stackoverflow.com/questions/50548207
复制相似问题