import feedparser
import webbrowser
import mysql.connector
mydb = mysql.connector(
host="localhost",
user="yourusername",
passwd="yourpassword",
database="mydatabase"
)
mycursor= mydb.cursor()
feed = feedparser.parse("https://stackoverflow.com/jobs/feed")
feed_entries= feed.entries
# feed_title = feed['feed']['title'] # NOT VALID
feed_entries = feed.entries
for entry in feed.entries:
job_title = entry.title
job_link = entry.link
job_published_at = entry.published # Unicode string
job_published_at_parsed = entry.published_parsed # Time object
# job_author = entry.author DOES NOT EXIST
content = entry.summary
# job_tags = entry.tags DOES NOT EXIST
sql="INSERT INTO entries (job_title,job_link,job_published_at,content) VALUES (%s,%s,%s,%s)"
val=(job_title,job_link,job_published_at,content)
mycursor.execute(sql,val)
mydb.commit()
print(mycursor.rowcount, "Record Inserted")
此代码从stackzoveflow RSS feed接收作业,并将其放入SQL数据库表中 我收到此编译错误: 追溯(最近一次通话): 在第3行的文件“ main.py”中 导入mysql.connector ModuleNotFoundError:没有名为“ mysql”的模块