python - 如何在 Scrapy 中使用 response.XPath 从多个标签中提取文本数据?

标签 python html css scrapy

我遇到了一个问题。我想在 scrapy 中使用 XPath 从以下 HTML 中提取文本。

<div class="block fix-text job-description">
   <p>We’re looking for an experienced <strong>Events Manager</strong> to develop and deliver our events and exhibitions programme, available to start as soon as possible. You’ll be leading a team of two to create and implement an events strategy that supports our corporate objectives. You’ll be working closely with our campaigns, marketing and projects teams to make sure we connect with our audiences and achieve event objectives.</p>
   <p>In this role, you’ll be working within a dynamic team in a fast-paced environment, with the potential opportunity to be part of the recruitment process to build your own team. Your experience as an events manager will have a strong marketing or digital marketing focus, ideally within a regulatory or third sector context.</p>
   <p>You’ll be managing high profile events across our diverse organisation, from workshops and online webinars to our national flagship conference. It’s an exciting role with the opportunity to help shape our current digital transformation and strengthen our brand, so we’re looking for creativity and innovation. You’ll also be working with senior colleagues and stakeholders, for whom you’ll prepare detailed briefings. In addition, you:</p>
   <ul>
      <li>Can demonstrate your extensive experience of creating and managing high profile events and conferences</li>
      <li>Have experience in delivering complex events programmes integrated into campaigns and marketing communications</li>
      <li>Have experience of audience research and insight</li>
      <li>Have excellent budget management and negotiation skills</li>
      <li>Are an outstanding communicator, both verbal and written</li>
      <li>Have strong people management skills with the ability to motivate and develop a team remotely</li>
   </ul>
   <p>This role is the opportunity to work within one of the largest healthcare regulators within the UK, shaping change within healthcare. As part of your salary and benefits package, you’ll receive:</p>
   <ul>
      <li>A good pension (15% employer contribution)</li>
      <li>25 days’ holiday a year (option to buy &amp; sell)</li>
      <li>Private Medical Insurance (PMI) &amp; Health screens</li>
      <li>Interest free ticket loans</li>
      <li>Exclusive discounts</li>
      <li>Employee assistance programme</li>
      <li>Childcare vouchers</li>
      <li>Cycle to work scheme</li>
      <li>Flexi-working</li>
      <li>The option to work from home up to 2 days a week.</li>
   </ul>
   <p>The General Medical Council (GMC) helps to protect patients and improve medical education and practice in the UK by setting standards for medical students and doctors. We support them in achieving (and exceeding) those standards and take action when they’re not met.</p>
   <p>A registered charity, we value diversity and inclusion because our differences make us stronger. So, our processes are fair, objective, transparent and free from discrimination.</p>
   <p><strong>Employment status: 12-month Fixed Term Contract</strong></p>
   <p><strong>Closing date: Midnight on Sunday 1st July 2018, late applications will not be accepted.</strong></p>
   <p><strong>Assessment date: Interviews &amp; Assessments will take place on Wednesday 11th July 2018</strong></p>
</div>

如何从上面的 HTML 中提取文本。 我尝试按照 XPath 提取文本

  1. ‘//*[@class=“job-description”]’

  2. //[@id=“main”]/div/div/div[1]/div[1]/div/div[2]/div[2]//text()

  3. //[@id=“main”]//div[@class=“job-description”]/’
  4. //div[@class=“job-description”]/p/text()
  5. '//div[@class="job-description"]/following-sibling::node()/descendant-or-self::text()'

6.'//div[@class="job-description"]/p/descendant-or-self::text()'

但是没有得到输出 谁能告诉我如何抓取这些信息,因为它在类中有多个 {p}​​ 标签,(ul} 标签。

所以现在我很困惑如何获取信息。

提前致谢

最佳答案

您并不是很清楚您想要什么,但听起来您想要一个能为您提供所有文本节点的 XPath 查询。你可以这样做:

/descendant::text()

关于python - 如何在 Scrapy 中使用 response.XPath 从多个标签中提取文本数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51055694/

相关文章:

python - 如何从 wunderground 中抓取动态表格

javascript - Javascript 关闭时处理特征检测

jquery - 在 html 中使用 css 放置悬停或单击输入类型

html - CSS "position: sticky"不粘

python - 我收到消息 : "The pexpect python module is required" when running pexpect module on ansible

python - 使用 python 将嵌套列表转换为行

javascript - 插入并执行javascript

javascript - 尝试使用 .hide() 隐藏内容时遇到问题

python - 计算边界框重叠的百分比,用于图像检测器评估

CSS:表格大小问题 (caption/tr/th/td)