-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArzt_Auskunft.py
62 lines (45 loc) · 2.08 KB
/
Arzt_Auskunft.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import scrapy
from time import sleep
import re
class DoctorSpider(scrapy.Spider):
name = "doctor"
start_urls = ['https://www.arzt-auskunft.de/neurologie/']
def __init__(self):
self.current_page_number = 1
self.scraped_pages = 0
def start_requests(self):
for url in self.start_urls:
yield scrapy.Request(url, callback=self.parse)
def parse(self, response):
d_urls = response.xpath('//a[@class="btn-detail"]/@href').getall()
for index, url in enumerate(d_urls):
yield scrapy.Request(url=url, callback=self.parse_item,
meta={'page_number': self.current_page_number, 'index': index})
self.current_page_number += 1
if self.current_page_number <= 91:
next_page_url = f"https://www.arzt-auskunft.de/neurologie/{self.current_page_number}/"
yield scrapy.Request(next_page_url, callback=self.parse, dont_filter=True)
def parse(self, response):
page_number = response.meta['page_number']
index = response.meta['index']
url = response.url
names = response.xpath('//h1[@class="fs2"]/text()').getall()
corrected_names = [' '.join(name.split()) for name in names]
addresses = response.xpath('//div[@itemprop="address"]/span/text()').getall()
corrected_address = [' '.join(address.split()) for address in addresses]
fax = response.xpath('//span[@itemprop="fax"]/text()').get()
fax = fax if fax else 'Not Available'
phone = response.xpath('//span[@itemprop="telephone"]/a/text()').get()
phone = phone if phone else 'Not Available'
yield {
'Page Number': page_number,
'Name': corrected_names,
'Address': corrected_address,
'Fax Number': fax,
'Phone Number': phone,
'Index': index,
'URL': url,
}
self.scraped_pages += 1
if self.scraped_pages >= 91:
return