在 XPATH 中我使用 '''...and'''要添加一个额外的标准,在cheerio中有这个选项吗?
我使用 Cheeriogs 库在 Google App 脚本中工作:
id 库: 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0
使用 =IMPORTXML('url','xpath')
我使用此 XPATH 进行调用:
//div[contains(@class, '匹配卡')和../../td[@class='score-time ']/a[contains(@href, 'matches')]]
这个想法是收集 div
包含 @class
以及单词 match-card
但是
他需要将 td
链接到 @class='score-time'
并且 a
包含 @href
单词 matches
我试图找到一种方法来用 CHEERIOGS 做到这一点,但它总是返回空白,我的尝试是:
$('tr:contains(td.score-time > a[href^="/matches/"]) > div[class^="match-card"]')
.each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
$('tr td.score-time:contains(a[href^="/matches/"]) > div[class^="match-card"]')
.each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
$('tr td.score-time > a[href^="/matches/"] > div[class^="match-card"]')
.each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
我如何才能实现我的预期结果?
通过评论中的请求提供更多信息:
示例链接:
https://int.soccerway.com/national/finland/suomen-cup/20212022/2nd-round/r67751/
预期结果是当嵌入蓝色链接时收集红色值:
I use the cheeriogs library to work in Google App Script:
id library: 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0
Using =IMPORTXML('url','xpath')
I make the call with this XPATH:
//div[contains(@class,'match-card') and ../../td[@class='score-time ']/a[contains(@href, 'matches')]]
The idea is to collect the div
that contain the @class
with the word match-card
BUT
he needs to have td
linked to @class='score-time'
and a
contains the @href
with the word matches
I tried to find a way to do this with CHEERIOGS but it always returns blank, my attempts were:
$('tr:contains(td.score-time > a[href^="/matches/"]) > div[class^="match-card"]')
.each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
$('tr td.score-time:contains(a[href^="/matches/"]) > div[class^="match-card"]')
.each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
$('tr td.score-time > a[href^="/matches/"] > div[class^="match-card"]')
.each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
How I could go about achieving my expected result?
Additional information via requests in the comments:
Example link:
https://int.soccerway.com/national/finland/suomen-cup/20212022/2nd-round/r67751/
The expected result is to collect the values in red when there are links embedded in blue:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的情况,以下修改后的脚本怎么样?
修改后的脚本:
结果:
当针对
https://int.soccerway.com/national/finland/suomen-cup/20212022/2nd-round/r67751/
的 URL 运行此脚本时,出现以下结果得到结果。In your situation, how about the following modified script?
Modified script:
Result:
When this script is run for the URL of
https://int.soccerway.com/national/finland/suomen-cup/20212022/2nd-round/r67751/
, the following result is obtained.这将是 :has 伪:
这可能在您使用的版本中不可用
That would be the :has pseudo:
This might not be available in the version you're using though