在您的情况下,以下选择器如何?
发件人:
const scrapurl = $('div.schema > div > div.tnms > div > a.tnmscn');
致:
const scrapurl = $('a.tnmscn[href^="/en/predictions"]');
const scrapurl = $('div.schema > div > div.tnms > div > a.tnmscn[href^="/en/predictions"]');
const scrapurl = $('div.schema > div > div.tnms > div > a[href^="/en/predictions"]');
-
/en/predictions-tips-wealdstone-solihull-moors-1455115
已检索。
-
href
在标签中
a
A.
和全班同学一起
tnmscn
是
/en/predictions
但是,从您使用的URL中检索到2个值。这一点我已经提过了
Granitosaurus's comment
如果要检索2个值,那么下面的修改如何?
修改脚本:
const url = "https://www.forebet.com/en/teams/wealdstone";
const contentText = UrlFetchApp.fetch(url).getContentText();
const $ = Cheerio.load(contentText);
const scrapurl = $('div.schema > div > div.tnms > div > a.tnmscn[href^="/en/predictions"]'); // and a.tnmscn[href^="/en/predictions"]
$(scrapurl).each(function() {
const urlmatch = $(this).attr('href');
console.log(urlmatch);
});