我尝试使用Cheerio和Puppeteer模块从HTML响应中删除电子邮件(my email@hotmail.com)。但是我得到了不同的东西,我根本不需要使用它们。
它在TD/TR中被列为P2类。
将tr作为参数放入
我的代码如下所示:
const puppeteer = require('puppeteer');
const $ = require('cheerio');
const url = 'https://mywebsite.com';
puppeteer
.launch()
.then(function(browser) {
return browser.newPage();
})
.then(function(page) {
return page.goto(url).then(function() {
return page.content();
});
})
.then(function(html) {
$('tr', html).each(function() {
// putting all the result into the list
console.log($(this).text());
});
})
.catch(function(err) {
//handle error
});
我正在测试这个输出:
移动式接线盒电路
邮箱:myemail@hotmail.com
电子邮件myemail@hotmail.com
经理
秘书
我只需要myemail@hotmail.com
这是我的HTML表:
E-mail