Advertisement
Yabbieo_

Webscraping

Sep 10th, 2021
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import smtplib,requests, re
  2. from email.mime.multipart import MIMEMultipart
  3. from email.mime.text import MIMEText
  4. from bs4 import BeautifulSoup
  5.  
  6. def sendEmail():
  7. #Email Account
  8. email_sender_account = "<email>"
  9. email_sender_username = "<username>"
  10. email_sender_password = "<password>"
  11. email_smtp_server = "<smtp>"
  12. email_smtp_port = <port>#Email Content
  13. email_recepients = ["<email>"]
  14. email_subject = "Black speaker Sale"
  15. email_body = "The speaker is currently on sale for $" + str(money) + ".Find at " + (url)
  16.  
  17. #login to email server
  18. server = smtplib.SMTP(email_smtp_server,email_smtp_port)
  19. server.starttls()
  20. server.login(email_sender_account, email_sender_password)
  21.  
  22. #For loop, sending emails to all email recipients
  23. for recipient in email_recepients:
  24. print(f"Sending email to {recipient}")
  25. message = MIMEMultipart('alternative')
  26. message['From'] = email_sender_account
  27. message['To'] = recipient
  28. message['Subject'] = email_subject
  29. message.attach(MIMEText(email_body, 'html'))
  30. text = message.as_string()
  31. server.sendmail(email_sender_account,recipient,text)
  32.  
  33. #All emails sent, log out.
  34. server.quit()
  35.  
  36. url = 'https://www.jbhifi.com.au/products/ultimate-ears-boom-3-portable-bluetooth-speaker-night-black'
  37. res=requests.get(url)
  38. res.raise_for_status() #checks to see if the site is downloaded
  39. soup =BeautifulSoup(res.text,'html.parser')
  40.  
  41. mySpan = soup.find_all("span", {"class": "sale"})
  42. if not mySpan:
  43. print("Item is not on sale yet")
  44. #I have no idea what i am doing for this for loop. None.
  45. for price in mySpan:
  46. currency, money = price.contents[:2]
  47. money=int(money)
  48. #print(money)
  49. if money <= int(180):
  50. sendEmail()
  51.  
  52. else:
  53. print('Not cheaper')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement