-
Notifications
You must be signed in to change notification settings - Fork 0
/
usman.py
33 lines (32 loc) · 1.02 KB
/
usman.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
import pymongo
myclient = pymongo.MongoClient("mongodb+srv://usman:[email protected]/test?retryWrites=true&ssl=true&ssl_cert_reqs=CERT_NONE")
mydb = myclient["jobsdata"]
mycol = mydb['jobs']
from bs4 import BeautifulSoup
import requests
soup = BeautifulSoup(requests.get('https://news.ycombinator.com/jobs',verify=False).content, "html.parser")
all_job =[]
alltr = soup.find_all("tr",{"class":"athing"})
for x in alltr:
full_des = x.find('a').text
try:
location = full_des.lower().split("in ")[1]
print (location)
except:
location = "NA"
print (location)
try:
company = full_des.lower().split("is hiring")[0]
print (company)
except:
company = "NA"
print (company)
try:
job = full_des.lower().split("is hiring")[1].split("in ")[0]
print (job)
except:
job = "NA"
print (job)
dummy = {'company':company,'job':job,'location':location}
#all_job.append(dummy)
main_insert = mycol.insert(dummy)