V
V
vovka_losira2019-05-20 12:43:44
MySQL
vovka_losira, 2019-05-20 12:43:44

How to parse data into mySQL table in Python?

Friends, I recently started learning to program in Python...
I'm trying to parse a list of titles of all series from LostFilms into mySQL table.
It turned out to find and display the names, but to push them into the table - no (

from bs4 import BeautifulSoup
import mysql.connector
import unicodedata





data_html = open('LF_all_ser.html',encoding='utf8').read()

soup = BeautifulSoup(data_html, 'html.parser')

All_names = soup.find_all('div', class_='name-ru')

i = 0

for div in All_names:
    a = div.get_text()
    i = i+1
    while i<10:
           conn = mysql.connector.connect(user = 'root', password = 'pass', host = 'localhost', database = 'test')
           cursor = conn.cursor()

           add_ser = 'INSERT INTO allser (id, name) VALUES (%s,%s)'
           data_ser = [ (i, a),]

           cursor.executemany(add_ser, data_ser)
           conn.commit()

writes - Incorrect string value: '\xD0\x9F\xD0\xBE\xD0\xBF...' for column 'name' at row 1
Apparently - some problem with the encoding or I'm just very stupid.
I pray for the help of elder brothers

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2019-05-20
@Rsa97

Wrong table column encoding and/or server connection.

V
Vladimir Kuts, 2019-05-20
@fox_12

Try running commands like

ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;

in the console mysql server
dbname and tablename just substitute your own...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question