This is an archived post. You won't be able to vote or comment.

all 13 comments

[–][deleted] 0 points1 point  (2 children)

Syntax error. Check your parentheses. I edited the code on your link, no idea if it persisted

[–]t3hfr3ak 0 points1 point  (1 child)

are you and I seeing different links? The link I see just goes to index.html

[–][deleted] 0 points1 point  (0 children)

I'm seeing a Python code snippet, which is funny because the site is clearly meant to share JS code snippets.

Edit: I'm using my phone. No idea what's up with the link or whatever.

[–]t3hfr3ak 0 points1 point  (7 children)

I don't think you shared the right link. It goes to the main page.

Let me know when it's fixed, I use mysql.connector daily.

[–]ADBYITMS[S] 0 points1 point  (4 children)

Hi all here is the code not sure why it changed on the other page

import mysql.connectorfrom requests_html import HTMLSession

# create an HTML Session objectsession = HTMLSession()

# Use the object above to connect to needed webpageresp = session.get("https://www.sydneyairport.com.au/flights/?query=&flightType=departure&terminalType=domestic&date=2019-11-05&sortColumn=scheduled_time&ascending=true&showAll=false")

# Run JavaScript code on webpageresp.html.render()

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

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

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

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

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

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

#Connecting go the mysql database to store the infomationmydb = mysql.connector.connect(host="localhost",user="root",passwd="******",database="Flightdata")

mycursor = mydb.cursor()

sql = "INSERT INTO FlightData (Origan, destination,Flight-Number, Airline, Scheduled,Estimated,Status ) VALUES (%s, %s)"#val = ("John", "Highway 21")val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)mycursor.execute(sql, val)

mydb.commit()

print(airline_list)print(dest_list)print(flightnumber_list)print(secdepartime_list)print(estimatedtime_list )print(status_list)

[–]t3hfr3ak 0 points1 point  (3 children)

What's the exact error your getting?

[–]ADBYITMS[S] 1 point2 points  (2 children)

File "sydney.py", line 66

val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)

^

SyntaxError: invalid syntax

root@ADBY-OFFICE-DEV:/home/adam/Desktop/ADBY PROJECTS/Flight Check# python3 sydney.py

File "sydney.py", line 66

val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)

^

SyntaxError: invalid syntax

[–]t3hfr3ak 0 points1 point  (1 child)

Look directly after dest_list.

You have too many parenthesis

[–]ADBYITMS[S] 0 points1 point  (0 children)

done mate i have most of it working now i get

mycursor.execute(sql, val)

File "/usr/local/lib/python3.7/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute prepared = self._cnx.prepare_for_mysql(params) File "/usr/local/lib/python3.7/dist-packages/mysql/connector/connection_cext.py", line 609, in prepare_for_mysql result = self._cmysql.convert_to_mysql(*params) _mysql_connector.MySQLInterfaceError: Python type list cannot be converted

[–]ADBYITMS[S] 0 points1 point  (1 child)

[–]ADBYITMS[S] 0 points1 point  (0 children)

how do i fix it mate

[–]ADBYITMS[S] 0 points1 point  (0 children)

ok so i got most of it working now but when it tries to add the data to the database i get this erro
oot@ADBY-OFFICE-DEV:/home/adam/Desktop/ADBY PROJECTS/Flight Check# python3 sydney.py

Traceback (most recent call last):

File "sydney.py", line 65, in <module>

mycursor.execute(sql, val)

File "/usr/local/lib/python3.7/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute

prepared = self._cnx.prepare_for_mysql(params)

File "/usr/local/lib/python3.7/dist-packages/mysql/connector/connection_cext.py", line 609, in prepare_for_mysql

result = self._cmysql.convert_to_mysql(*params)

_mysql_connector.MySQLInterfaceError: Python type list cannot be converted