【发布时间】:2020-05-07 09:23:56
【问题描述】:
我正在尝试在线查找数据列表,并且我想将输出写入 csv 文件中的字典列表。 例如,我想将“结果”导出到 CSV
if resp.status_code == 200:
soup = BeautifulSoup(resp.content, "html.parser")
results = []
for g in soup.find_all('div', class_='r'):
anchors = g.find_all('a')
if anchors:
link = anchors[0]['href']
title = g.find('h3').text
item = {
"title": title,
"link": link
}
results.append(item)
print(results)
【问题讨论】:
标签: python python-3.x pandas csv