-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscrape_all.py
43 lines (33 loc) · 1.22 KB
/
scrape_all.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
# Built-in imports
from os import getenv
from os.path import join, realpath
from time import sleep
from json import loads
from urllib.request import urlretrieve
# Package imports
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
# Local imports
from ..utils.fb_regexes import find_and_remove, regex_in, re_line_with_characters, re_guests, re_three_letter_two_digit_date, re_utc_time, re_utc_and_more
from ..Event import Event
from .driver import setup_driver
from ..utils.url_converter import facebook_www_to_locale
from .scrape_events_page import scrape_events_page
""" PARSING FUNCTIONS """
def scrape_all(driver, pages: list[str], img_dir: str):
""" RUNNING PARSE FUNCTIONS ON PAGES """
img_dir = realpath(img_dir) # Directory where images get stored
events = []
for page in pages:
driver.get(page)
sleep(20)
try:
events.extend(scrape_events_page(driver, page, img_dir))
except NoSuchElementException as e:
print(f"Error parsing {page}")
print("No events found.")
print(e)
except Exception as e:
print(f"Error parsing {page}")
raise e
return events