-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (56 loc) · 2 KB
/
main.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
63
64
65
import logging
import os
from itertools import product
import numpy as np
import pandas as pd
from src.Mailanalyzer import extract_emails_from_websites
from src.Scrapper import WebDriver
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
CHROME_DRIVER_PATH = "chromedriver"
def main() -> None:
data_folder = "data"
# Check if the data folder exists
if not os.path.exists(data_folder):
# If it doesn't exist, create the data folder
os.mkdir(data_folder)
logging.info(f"Data folder '{data_folder}' created successfully.")
else:
logging.info(f"Data folder '{data_folder}' already exists.")
url = "https://www.google.com/maps"
leads = []
regions = ["brussels"]
business_types = ["restaurant", "traiteur", "hotel", "centre sport"]
for region, business_type in product(regions, business_types):
logging.info(f"Scrapping {business_type} in {region}")
try:
Scrapper = WebDriver(
CHROME_DRIVER_PATH=os.path.abspath(CHROME_DRIVER_PATH),
headless=False)
data = Scrapper.scrape(url, f"{business_type} in {region}")
data = list(
map(
lambda item: {
**item,
"region": region,
"Business Type": business_type,
},
data,
)
)
leads.extend(data)
except Exception as e:
logging.error(e)
pass
logging.info("Exporting the results")
leads = pd.DataFrame(leads)
leads["website"] = leads["website"].apply(
lambda site: "https://www." + str(site) if pd.notna(site) else np.nan
)
leads.to_csv("data/adresses.csv", index=False)
logging.info("Analysing mails")
leads = extract_emails_from_websites(leads)
leads.to_csv("data/adresses_complete.csv", index=False)
if __name__ == "__main__":
main()