Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_html(url):
- req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
- response = urllib.request.urlopen(req)
- return response.read()
- def add_to_db(chars, desc):
- conn = pymysql.connect(host='localhost',
- port=3307,
- user='***',
- password='***',
- db='***',
- charset='utf8',
- cursorclass=pymysql.cursors.DictCursor)
- global _id
- with conn.cursor() as cursor:
- sql = "INSERT INTO `articles` (`id_cat`, `characteristics`, `description`) VALUES (%s, %s, %s)"
- cursor.execute(sql, (_id, chars, desc))
- conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement