0

我开始学习scrapy,想知道如何在excel文件中按州获取每所学校的信息。每个状态都是指向另一个页面的链接,我不确定如何为此编写 xpath 语法。请指教。

https://www.raise.me/high-school

import scrapy
class RaisemeSpider(scrapy.Spider):
    name = 'raiseme'
    allowed_domains = ['raise.me/high-school']
    start_urls = ['http://raise.me/high-school/']
    def parse(self, response):
        h1_tag = response.xpath('//h1/text()').extract_first()
        yield {'H1 Tag': h1_tag }
4

1 回答 1

0

您可以使用以下方式提取指向不同状态的链接response.xpath('//*[contains(@class, "links-list-list-item")]/a/@href').get()

SelectorGadget 是提取 xpath 和 css 选择器的有用扩展。请记住在开发工具中禁用 javascript。对于在 scrapy shell(没有 javascript)和浏览器(使用 javascript)中加载的网站,源代码会有所不同。

于 2021-03-20T18:25:51.660 回答