I'm currently making a program which searches through the BBC News website and adds each headline to a MySQL database using the mysql.connector and newspaper libraries. I've written the following code but nothing happens when I run it, I was wondering what I'm doing wrong? Apologies if it's just a simple mistake :)
import mysql.connector
import newspaper
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
database="headlines"
)
search = newspaper.build('https://www.bbc.co.uk/news')
for article in search.articles:
mycursor = mydb.cursor()
sql = "insert into headlines (headline) values (%s)", (article.title)
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, "headlines inserted.")