【发布时间】:2019-02-08 09:32:00
【问题描述】:
我也需要从 xml 查询中获取空值,该查询将链接作为结果数组返回。有些度数没有链接可以参考。打印时,不会打印相应的空结果。
目的是获取相应度数的链接。
我的代码是:
postgraduatedegrees=tree.xpath('//*[@id="block-scholarly-
content"]/div/article/div/div/div//*[contains(text(),"Degree
of")]/text()')
postgraduatedegreeslinks=tree.xpath('//*[@id="block-scholarly-
content"]/div/article/div/div/div//*[contains(text(),"Degree of")]/@href')
Output:
len(postgraduatedegrees)
Out[222]: 52
len(postgraduatedegreeslinks)
Out[223]: 40
空值被删除。 请帮我解决问题
【问题讨论】: