Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. def get_html(url):
  2. req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
  3. response = urllib.request.urlopen(req)
  4. return response.read()
  5.  
  6. def add_to_db(chars, desc):
  7. conn = pymysql.connect(host='localhost',
  8. port=3307,
  9. user='***',
  10. password='***',
  11. db='***',
  12. charset='utf8',
  13. cursorclass=pymysql.cursors.DictCursor)
  14.  
  15. global _id
  16. with conn.cursor() as cursor:
  17. sql = "INSERT INTO `articles` (`id_cat`, `characteristics`, `description`) VALUES (%s, %s, %s)"
  18. cursor.execute(sql, (_id, chars, desc))
  19. conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement