Created
October 4, 2020 16:51
-
-
Save Abhayparashar31/1236b935cf9f7458969acc0069fee247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.base import MIMEBase | |
from email import encoders | |
from bs4 import BeautifulSoup | |
import requests | |
import csv | |
name = input("Job name:\n").replace(" ","-") | |
city = input("City name:\n") | |
state = input("State name:\n") | |
res = requests.get(f'https://www.indeed.co.in/{name}-jobs-in-{city},-{state}') | |
soup = BeautifulSoup(res.text,'html.parser') | |
job_name = soup.select('.jobtitle') | |
for i in range(len(job_name)): | |
job_name = soup.select('.jobtitle')[i].getText().strip() | |
job_company = soup.select('.company')[i].getText().strip().replace(","," ") | |
job_location = soup.select('.location')[i].getText().strip().replace(","," ") | |
try : | |
job_money = soup.select(".salaryText")[i].getText() | |
except : | |
job_money = "" | |
h2 = soup.find('h2',{'class':'title'}) | |
a = h2.find('a') | |
link = a.attrs.get("href") | |
url = "https://www.indeed.co.in"+link | |
row = [job_name,job_company,job_location,job_money,url] | |
#print(row) | |
with open('jobs.csv', 'a',newline="\n",encoding="utf-8") as f: | |
writer = csv.writer(f) | |
writer.writerow(row) | |
email_user = 'sender_email' | |
email_password = 'sender_password' | |
email_send = 'receiver_email' | |
subject = 'JOBS THAT BEST SUITS YOU' | |
msg = MIMEMultipart() | |
msg['From'] = email_user | |
msg['To'] = email_send | |
msg['Subject'] = subject | |
body = 'THIS IS THE DAILY REMINDER CSV MAIL SENDING YOU LATEST JOBS FROM TODAY' | |
msg.attach(MIMEText(body,'plain')) | |
filename='jobs.csv' | |
attachment =open(filename,'rb') | |
part = MIMEBase('application','octet-stream') | |
part.set_payload((attachment).read()) | |
encoders.encode_base64(part) | |
part.add_header('Content-Disposition',"attachment; filename= "+filename) | |
msg.attach(part) | |
text = msg.as_string() | |
server = smtplib.SMTP('smtp.gmail.com',587) | |
server.starttls() | |
server.login(email_user,email_password) | |
server.sendmail(email_user,email_send,text) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment