java - 在美丽的汤中将检索到的数据保存到 CSV
问题描述
for row in page_soup.find("table",{"class":"table"}).tbody.findAll('tr'):
first_column = row.findAll('td')[0].contents
second_column = row.findAll('td')[1].contents
third_column = row.findAll('td')[2].contents
print(first_column, second_column, third_column)
解决方案
你可以从简单的事情开始:
for row in page_soup.find("table",{"class":"table"}).tbody.findAll('tr'):
first_column = row.findAll('td')[0].contents
second_column = row.findAll('td')[1].contents
third_column = row.findAll('td')[2].contents
print("\"" + first_column + "\",", "\"" + second_column + "\",", "\"" + third_column + "\"")
并将输出重定向到文件中。但是,这假定每列都有一个可能正确也可能不正确的字符串。如果列类型是数字,则删除转义的引号。
推荐阅读
- c++ - 用于创建线程并加入可变数量线程的循环
- android - “windowSoftInputMode=stateHidden”不适用于 Instant Run
- ios - 如何检查 Firebase 实时数据库中是否已存在 childByAutoID()?
- c++ - libclang 可以告诉我一个函数是否有弱链接吗?
- c# - C# DataGridView 行未显示 - Windows 窗体已损坏
- c++ - 从二叉搜索树中删除节点 - 错误答案
- centos7 - 如何卸载 ArangoDB
- azure - 如何控制 Azure Event Grid 触发器的并发性
- javascript - 带有 JavaScript 变量的 SVG 旋转问题
- spring - Spring Boot Admin Console 2.0.4 如何使墙板不安全?