Guest User

Untitled

a guest
Oct 21st, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import MySQLdb as sql
  2. from urllib2 import urlopen
  3.  
  4. def get_query(c,x):
  5.      c.execute(x)
  6.      return c.fetchall()
  7.  
  8. def get_page(url):
  9.     urlopen(url)
  10.     page = urlopen.read()
  11.     return page
  12.  
  13.  
  14. host='localhost'
  15. port=3306
  16.  
  17. db='bantictest'
  18. user='root'
  19. password='insertmehere'
  20.  
  21.  
  22.  
  23. #Connect to mysql
  24. sql_connection = sql.connect(host=host,
  25.                             user=user,
  26.                             passwd=password,
  27.                             db=db,
  28.                             port=port)
  29.  
  30. cursor = sql_connection.cursor()
  31.  
  32. #Query
  33. response = get_query(cursor,"select * from queued")
  34. url = response[0][2] #select the first result's url
  35.  
  36. #Save page
  37. page = get_page(url)
  38. webfile = open('./webpage.html', 'w')
  39. webfile.write(page)
  40. webfile.close()
  41.  
  42. #connection.commit()  #If you make any changes to the database, you need this
  43. connection.close()
Add Comment
Please, Sign In to add comment