【发布时间】:2019-11-30 02:43:19
【问题描述】:
我正在抓取这个网站:https://www.oddsportal.com/darts/europe/european-championship/results/
这个网站使用 javascript 渲染表格数据,因此我在 docker 容器中使用了 scrapy-splash 插件。
我想在遍历选择器列表“tableRows”时过滤掉所有具有“dark center”类的行。 但是在迭代时,xpath 选择器会在每次迭代时查询与每个项目相对的整个 SelectorList
tableRows = response.xpath('//table[contains(@id, "tournamentTable")]/tbody/tr')
for row in tableRows:
print(row)
if row.xpath('//*[contains(@class, "dark center")]') is not None:
print(True)
我的输出:
<Selector xpath='//table[contains(@id, "tournamentTable")]/tbody/tr' data='<tr class="dark center" xtid="39903"><th'>
True
<Selector xpath='//table[contains(@id, "tournamentTable")]/tbody/tr' data='<tr class="center nob-border"><th class='>
True
为什么类'center nob-border'返回True?
【问题讨论】:
标签: python python-3.x scrapy