-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
74 lines (62 loc) · 1.93 KB
/
script.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
66
67
68
69
70
71
72
73
74
"""
This script uses requests and OpenAI to scrape the web & find relevant job postings.
The script works for most pages except:
1. Careers pages that are dynamically generated
a. Most larger companies that have a shit ton of job postings that are dynamically grouped
b. Most companies that host on Ashby
2. Careers pages on websites with bot verifiers (will return a 403 forbidden)
3. Job postings on specific listings
a. Wellfound
b. YC
c. LinkedIn
"""
import os
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
from bs4 import BeautifulSoup
import openai
from board_page import BoardPage
from listing_page import ListingPage
openai.api_key = os.getenv("OPENAI_API_KEY")
URL = "http://careers.hebbia.ai/"
ROLE_KEYWORDS = [
# Ops
"BizOps",
"Operations",
"Chief of Staff",
"Business",
"Strategy",
# Marketing
"Marketing",
"Growth",
"Community",
# Sales
"Sales",
]
def open_and_create_soup(url: str) -> BeautifulSoup:
"""
Requests and creates a bs4 object from url
"""
req = Request(url=url, headers={"User-Agent": "Mozilla/5.0"})
try:
with urlopen(req) as f:
page = f.read().decode("utf-8")
except HTTPError as e:
print("HTTPError on request:", e)
except URLError as e:
print("URLError on request:", e)
else:
return BeautifulSoup(page, "html.parser")
return None
# Create a new BoardPage
board_page = BoardPage(open_and_create_soup(URL), URL)
relevant_role_links = board_page.scrape_all_relevant_roles(ROLE_KEYWORDS)
base_url = board_page.get_ats_base_url()
listing_pages = []
for relevant_role_link in relevant_role_links:
listing_page = ListingPage(
open_and_create_soup(relevant_role_link), relevant_role_link, base_url=base_url
)
print(listing_page.scrape_job_title())
print(listing_page.scrape_job_description())
listing_pages.append(listing_page)