Python Forum
error when inserting list statement from python to MySQL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error when inserting list statement from python to MySQL
HI all i am trying to insert data from a python script i have and i am getting an error, i thank you for your help in advance and feel free to let me know if there is a better way to do what I am trying to do here , as i am still new to coding with python any help would be good, i will be adding other locations soon as please letme know if that would be best to do each with another file or all in the one
import mysql.connector
from requests_html import HTMLSession

# create an HTML Session object
session = HTMLSession()

# Use the object above to connect to needed webpage
resp = session.get("")

# Run JavaScript code on webpage

# parse <span class="with-image"> elements containing airline names
airline_list = []
airline_spans = resp.html.find('.with-image')
for span in airline_spans:

# parse <div class="city-name"> elements containing airline names
dest_list = []
dest_divs = resp.html.find('.city-name')
for span in dest_divs:

# parse <div class="flight-numbers"> elements containing Flight numbers
flightnumber_list = []
flightnumber_divs = resp.html.find('.flight-numbers')
for span in flightnumber_divs:

# parse <div class="heading-large"> elements containing Sec depart time
secdepartime_list = []
secdepartime_divs = resp.html.find('.large-scheduled-time')
for span in secdepartime_divs:

# parse <div class="estimated-time"> elements containing estimated-time
estimatedtime_list = []
estimatedtime_divs = resp.html.find('.estimated-time')
for span in estimatedtime_divs:

# parse <div class="estimated-time"> elements containing latesttime
status_list = []
status_divs = resp.html.find('.status-container')
for span in status_divs:

#Connecting go the mysql database to store the infomation

mydb = mysql.connector.connect(
print("Adding Sydney Domestic Airport Flight Information to the Database")
mycursor = mydb.cursor()
sql = "INSERT INTO FlightData (Origan, destination,Flight-Number, Airline, Scheduled,Estimated,Status ) VALUES (%s, %s)"
val = ("Sydney", dest_list, flightnumber_list, airline_list, secdepartime_list, estimatedtime_list, status_list)
mycursor.execute(sql, val)

Messages In This Thread
error when inserting list statement from python to MySQL - by ADBYITMS - Nov-10-2019, 10:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  error in python and mysql statement vj78 4 786 Apr-08-2021, 02:08 PM
Last Post: vj78
  Python and MYSQL Resultset vj78 2 673 Apr-02-2021, 12:41 AM
Last Post: vj78
  Python/BeautiifulSoup. list of urls ->parse->extract data to csv. getting ERROR IanTheLMT 2 1,909 Jul-04-2019, 02:31 AM
Last Post: IanTheLMT
  mysql database error brecht83 1 3,484 Dec-14-2018, 01:25 PM
Last Post: jeanMichelBain
  Inserting multiple cookies using python requests freshtomatoes 0 3,207 Aug-16-2018, 09:25 PM
Last Post: freshtomatoes
  Q. Nested for statement in list type ives 3 1,596 Mar-14-2018, 07:30 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020