-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestMay31.py
More file actions
186 lines (116 loc) · 5.34 KB
/
Copy pathtestMay31.py
File metadata and controls
186 lines (116 loc) · 5.34 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<<<<<<< HEAD
driver=webdriver.Firefox(executable_path=DRIVER_EXE)
page_number=0
for page_number in range(0,3):
mydict={'q':job_search_keywords,
'l':job_search_location,
'sort':job_search_sortbydate,
'start':search_result_pg}
resp_make_url=requests.get(base_url,params=mydict)
searched_url=resp_make_url.url
#loop through one page of searched results:
#creating a response object called resp
resp = requests.get(searched_url)
#You can find out what encoding Requests is using, and change it, using the r.encoding property
#print(resp.encoding)
# Running the url link through BeautifulSoup give us a BeautifulSoup object, which represents the document as a nested data structure.
start_soup = BeautifulSoup(resp.content)
urls = start_soup.findAll('a',{'rel':'nofollow','target':'_blank'}) #this are the links of the job posts
urls = [link['href'] for link in urls]
#print job links of the current search result page:
for i in range(len(urls)): #change it back to for i in range(len(urls)):
get_info = True
try:
driver.get(original_url+urls[i]) #The driver.get method will navigate to a page given by the URL.
except TimeoutException:
get_info = False
except IndexError:
get_info = False
continue
j = random.randint(1000,2200)/1000.0
time.sleep(j) #waits for a random time so that the website don't consider you as a bot
if get_info:
soup=BeautifulSoup(driver.page_source)
#head_tag=soup.head.title
#title_tag = head_tag.contents[0]
#print(title_tag)
#job_title=soup.b.string
job_title=soup.find_all("b",{"class":"jobtitle"})[0]
print(job_title.text)
company=soup.find_all("span",{"class":"company"})[0]
print(company.text)
location=soup.find_all("span",{"class":"location"})[0]
print(location.text)
job_description=soup.find_all("span",{"id":"job_summary"})[0]
#print(job_description.text)
#print (driver.current_url)
jobs={
"Job Title":job_title.text,
"Company Name":company.text,
"Location":location.text,
"Url":driver.current_url,
"Job Description":job_description.text
}
collection.insert(jobs)
#move to the next page of searched results
search_result_pg+=10
#print(page_number)
=======
driver=webdriver.Firefox(executable_path=DRIVER_EXE)
page_number=0
for page_number in range(0,3):
mydict={'q':job_search_keywords,
'l':job_search_location,
'sort':job_search_sortbydate,
'start':search_result_pg}
resp_make_url=requests.get(base_url,params=mydict)
searched_url=resp_make_url.url
#loop through one page of searched results:
#creating a response object called resp
resp = requests.get(searched_url)
#You can find out what encoding Requests is using, and change it, using the r.encoding property
#print(resp.encoding)
# Running the url link through BeautifulSoup give us a BeautifulSoup object, which represents the document as a nested data structure.
start_soup = BeautifulSoup(resp.content)
urls = start_soup.findAll('a',{'rel':'nofollow','target':'_blank'}) #this are the links of the job posts
urls = [link['href'] for link in urls]
#print job links of the current search result page:
for i in range(len(urls)): #change it back to for i in range(len(urls)):
get_info = True
try:
driver.get(original_url+urls[i]) #The driver.get method will navigate to a page given by the URL.
except TimeoutException:
get_info = False
except IndexError:
get_info = False
continue
j = random.randint(1000,2200)/1000.0
time.sleep(j) #waits for a random time so that the website don't consider you as a bot
if get_info:
soup=BeautifulSoup(driver.page_source)
#head_tag=soup.head.title
#title_tag = head_tag.contents[0]
#print(title_tag)
#job_title=soup.b.string
job_title=soup.find_all("b",{"class":"jobtitle"})[0]
print(job_title.text)
company=soup.find_all("span",{"class":"company"})[0]
print(company.text)
location=soup.find_all("span",{"class":"location"})[0]
print(location.text)
job_description=soup.find_all("span",{"id":"job_summary"})[0]
#print(job_description.text)
#print (driver.current_url)
jobs={
"Job Title":job_title.text,
"Company Name":company.text,
"Location":location.text,
"Url":driver.current_url,
"Job Description":job_description.text
}
collection.insert(jobs)
#move to the next page of searched results
search_result_pg+=10
#print(page_number)
>>>>>>> 42f569604d9f1629a860800d13314643a37f75e9
#print(searched_url) # print urls for search result page 1, 2 ,3