大家好,我现在有这个:
import feedparser
d = feedparser.parse('http://store.steampowered.com/feeds/news.xml')
for i in range(10):
print d.entries[i].title
print d.entries[i].date
我该怎么做才能使标题和日期在同一行?也不需要打印,我只是在那里测试,我想转储到一个mysql数据库的标题和日期,任何帮助是非常感谢!
最佳答案
如果要在同一行上打印,只需添加逗号:
print d.entries[i].title, # <- comma here
print d.entries[i].date
要插入到MySQL,您需要执行以下操作:
to_db = []
for i in range(10):
to_db.append((d.entries[i].title, d.entries[i].date))
import MySQLdb
conn = MySQLdb.connect(host="localhost",user="me",passwd="pw",db="mydb")
c = conn.cursor()
c.executemany("INSERT INTO mytable (title, date) VALUES (%s, %s)", to_db)