-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
65 lines (61 loc) · 1.8 KB
/
test.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
from bs4 import BeautifulSoup
import requests
import csv
import time
import random
rows = []
jobs = []
keys = ['\b', "Bank", "Banking", "Finance"]
siteURL = "http://www.simplyhired.com"
baseURL = "http://www.simplyhired.com/search?q=%s&l="
testURL = "http://www.simplyhired.com/search?q=system+engineer+bank+&l="
def getCompanies(oldSoup):
menu = oldSoup.find("div", class_="dropdown-submenu")
items = menu("a", class_="dropdown-item")
for item in items:
row.append(item.string)
href = item.get('href')
if href != None:
url = siteURL + href
r = requests.get(url)
data = r.text
localSoup = BeautifulSoup(data, 'html.parser')
sentence = localSoup.find("div", class_="posting-text")
if sentence != None:
numberOfJobs = sentence.string
number = numberOfJobs.split(' ')[-1]
row.append(number)
else:
print("rude")
row.append('0') #no matches found
time.sleep(random.randrange(20,60))
with open('jobs.csv') as infile:
lines = csv.reader(infile)
for line in lines:
word = line[0]
if word != '':
word = word.replace(' ', '+')
jobs.append(word)
for job in jobs:
for key in keys:
search = job + "+" + key
row = [search.replace('+', ' ')]
url = baseURL % search
r = requests.get(url)
data = r.text
soup = BeautifulSoup(data, 'html.parser')
sentence = soup.find("div", class_="posting-text")
if sentence != None:
numberOfJobs = sentence.string
number = numberOfJobs.split(' ')[-1]
row.append(number)
getCompanies(soup)
print("Finished %s!" % search)
else:
print("rude")
row.append("No Matches Found") #no matches found
rows.append(row)
with open('test.csv', 'w', encoding="utf-8", newline='') as infile:
rowWriter = csv.writer(infile)
for row in rows:
rowWriter.writerow(row)