daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Import requests (to download the page)
  2. import requests
  3.  
  4. # Import BeautifulSoup (to parse what we download)
  5. from bs4 import BeautifulSoup
  6.  
  7. # Import Time (to add a delay between the times the scape runs)
  8. import time
  9.  
  10. # Import smtplib (to allow us to email)
  11. import smtplib
  12.  
  13. # This is a pretty simple script. The script downloads the homepage of VentureBeat, and if it finds some text, emails me.
  14. # If it does not find some text, it waits 60 seconds and downloads the homepage again.
  15. i = 0
  16. # while this is true (it is true by default),
  17. while True:
  18.     # set the url as VentureBeat,
  19.     url = "https://www.dropbox.com/sh/xbp0hkp5793mnio/AADVOxmLRL0mm8HG49mnfHqqa?dl=0"
  20.     # set the headers like we are a browser,
  21.     headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
  22.     # download the homepage
  23.     response = requests.get(url, headers=headers)
  24.     # parse the downloaded homepage and grab all text, then,
  25.     soup = BeautifulSoup(response.text, "lxml")
  26.     files = str(soup).count('sl-grid-cell')
  27.  
  28.     print("n: {}\tfiles: {}".format(i, files))
  29.     i += 1
  30.     # if the number of times the word "Google" occurs on the page is less than 1,
  31.     if files == 13 or files == 0:
  32.         # wait 60 seconds,
  33.         time.sleep(60)
  34.         # continue with the script,
  35.         continue
  36.  
  37.     # but if the word "Google" occurs any other number of times,
  38.     else:
  39.         # create an email message with just a subject line,
  40.         print('Saiu SD!')
  41.         msg = """Saiu SD!
  42.        https://www.dropbox.com/sh/xbp0hkp5793mnio/AADVOxmLRL0mm8HG49mnfHqqa?dl=0"""
  43.         # set the 'from' address,
  44.         fromaddr = 'saiusd1234@gmail.com'
  45.         # set the 'to' addresses,
  46.         toaddrs  = ['joviolcunha@gmail.com', 'dvdrft@gmail.com', 'kmilla_njb@hotmail.com']
  47.  
  48.         # setup the email server,
  49.         server = smtplib.SMTP('smtp.gmail.com', 587)
  50.         server.starttls()
  51.         # add my account login name and password,
  52.         server.login("saiusd1234@gmail.com", "saiusd1234*")
  53.  
  54.         # Print the email's contents
  55.         print('From: ' + fromaddr)
  56.         print('To: ' + str(toaddrs))
  57.         print('Message: ' + msg)
  58.        
  59.         # send the email
  60.         server.sendmail(fromaddr, toaddrs, msg)
  61.        
  62.         # disconnect from the server
  63.         server.quit()
  64.  
  65.         break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top