scraper.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:parity-in-the-senate 作者: seansegal 项目源码 文件源码
def write_to_csv(file, all_data):
    senators = set()
    for bill in all_data:
        for vote in bill['votes']:
            senators.add(vote['senator'])
    headers = ['description', 'date']
    headers.extend(senators)

    with open(file, 'w') as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=headers, restval='N/A')
        writer.writeheader()
        for bill in all_data:
            row = {
                'description': bill['description'],
                'date': bill['date'].replace(',', '/')
            }
            row.update({b['senator']: b['voted'] for b in bill['votes']})
            writer.writerow(row)

# Save data to JSON
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号