我正在尝试从CSV文件列表中解析多个供稿(500),并将结果保存到另一个CSV文件中。问题是解析器仅遍历列表中的一个提要。
writer = csv.writer(open('items.csv', 'w'))
reader = csv.reader(open('feeds.csv', 'r'))
next(reader) # skip column headings
for row in reader:
url = row[0]
print (url)
df = pd.DataFrame(row)
df = pd.DataFrame(columns=['author', 'title', 'link','summary', 'published'])
for i, post in enumerate(feed.entries):
df.loc[i] = post.author, post.title, post.link, post.summary, post.published
df
答案 0 :(得分:0)
我终于解决了我的问题,这是如果将来有人遇到类似问题的最终代码
import feedparser
import csv
import pandas as pd
reader = csv.reader(open('feeds.csv', 'r'))
next(reader) # column headings
df = pd.DataFrame(columns=['author', 'title', 'link','summary', 'published'])
for row in reader:
url = row[0]
print (url)
feed = feedparser.parse(url)
for i, post in enumerate(feed.entries):
df.loc[len(df)] = post.author, post.title, post.link, post.summary, post.published
df.to_csv('myfilename.csv', index=False)