[英]Scrape text after ::before (xpath, css)
我已经构建了一个 Scrapy Spider 并希望从以下位置获取 email 文本:
::before "E-Mail" "E-Mail I would like to scrape"
我试过:'email': response.css('#content > div.segment.morecontact.clearfix > div > div.secondary > ul > li:nth-child(1) > a > i::text') .extract(),但我只收到“电子邮件”而不是实际地址
您需要一个简单的 XPath 的following-sibling::*
:
email = response.xpath('//i[contains(@class, "icon_email")]/following-sibling::text()[1]').get()
您可以使用另一种方法并从href
属性获取 email: email = response.xpath('//a[i[contains(@class, "icon_email")]]/@href').re_first(r'mailto:(. +)')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.