使用Scrapy从Ajax表单请求中获取数据

2024-09-29 23:31:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从这个网站上搜集所有医院的数据。 https://www.german-hospital-directory.com/search/Bundesland/Baden-Wuerttemberg.html。在

在查看请求之后,它发出一个表单请求。而且它不能通过废壳

enter image description here

并给出整个html的响应。如何提取每个医院的数据,如URL、名称、图像和遍历所有医院。任何帮助都将是感激的,因为我是新来刮。在

我需要使用硒还是可以用scrapy来达到这个目的。在


Tags: 数据httpscom表单search网站htmlwww
1条回答
网友
1楼 · 发布于 2024-09-29 23:31:30

您需要先GET您的URL(以接收cookies):https://www.german-hospital-directory.com/search/Bundesland/Baden-Wuerttemberg.html

但接下来您需要GET这个URL https://www.german-hospital-directory.com/search/_files/main-search/Suchergebnis.jsf

像这样:

start_urls = ['https://www.german-hospital-directory.com/search/Bundesland/Baden-Wuerttemberg.html']

def parse(self, response):

    yield scrapy.Request(

        url="https://www.german-hospital-directory.com/search/_files/main-search/Suchergebnis.jsf",
        callback=self.parse_hospitals
    )

def parse_hospitals(self, response):
    #here you have hospitals data
    .....

相关问题 更多 >

    热门问题