【发布时间】:2019-12-19 14:03:31
【问题描述】:
这是我的有效代码:
name = selector.xpath('//title/text()').get()
print(name)
以上代码的输出:
No broker | Crunchbase
但是对于以下代码,它不起作用:
##Intro of the company
intro = selector.xpath('//a[contains(@class,"component--field-formatter field-type-text_long ng-star-inserted")]/text()')
print(intro)
以上代码的输出:
[<Selector xpath='//a[contains(@href,"location_identifiers")]/text()' data=' Bangalore'>, <Selector xpath='//a[contains(@href,"location_identifiers")]/text()' data=' Karnataka'>, <Selector xpath='//a[contains(@href,"location_identifiers")]/text()' data=' India'>, <Selector xpath='//a[contains(@href,"location_identifiers")]/text()' data=' India'>]
这是网址: https://www.crunchbase.com/organization/nobroker#section-overview
如何才能在第二个代码中仅获得印度卡纳塔克邦班加罗尔? 我认为问题出在 /text? 第一个 /text 有效,但第二个无效。我应该如何使其仅获取文本? 非常感谢!! 如果您能向我推荐一些关于如何使用硒选择器抓取 sn-ps 数据的文档,我们将不胜感激。
谢谢!
【问题讨论】:
标签: python html selenium xpath