【问题标题】:Scrape text after ::before (xpath, css)在 ::before (xpath, css) 之后抓取文本
【发布时间】:2019-11-16 10:43:51
【问题描述】:

我已经构建了一个 Scrapy Spider,并希望从以下地址获取电子邮件文本:

::前 “电子邮件” “我想抓取的电子邮件”

我试过:'email' : response.css('#content > div.segment.morecontact.clearfix > div > div.secondary > ul > li:nth-child(1) > a > i:: text').extract(),但我只收到“电子邮件”而不是实际地址

【问题讨论】:

  • 你能把实际的html sn-p发过来吗
  • 当然,这可能是一个愚蠢的问题,但究竟如何?我可以拍照并裁剪吗?谢谢
  • 这里是直接链接,我需要来自 icon.icon_email 类的电子邮件
  • 你能突出你要刮的部分,给我截图。我会给你发送 xpath 表达式

标签: python xpath scrapy css-selectors


【解决方案1】:

你需要一个简单的 XPath 的following-sibling::*:

email = response.xpath('//i[contains(@class, "icon_email")]/following-sibling::text()[1]').get()

您可以使用另一种方法并从href 属性获取电子邮件: email = response.xpath('//a[i[contains(@class, "icon_email")]]/@href').re_first(r'mailto:(.+)')

【讨论】:

  • 非常感谢,稍后我会尝试并回信!再次感谢
  • 嘿,谢谢它的工作,但现在我看到,一些电子邮件文本在跨度下是彼此的,所以我只得到电子邮件文本的开头部分。有没有办法连接整个电子邮件文本?例如: 'in' 'fo@' 'some' 'text' '.com' 之间总是有一个 span 类。再次感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-02
  • 2017-07-23
  • 2013-10-03
  • 2013-11-14
  • 2020-12-29
  • 2020-12-18
  • 2016-08-11
相关资源
最近更新 更多