如何将 HTML 表格抓取为 CSV? [英] How can I scrape an HTML table to CSV?
问题描述
问题
我在工作中使用了一个工具,它可以让我进行查询并取回 HTML 信息表.我没有任何后端访问权限.
如果我可以将这些信息放入电子表格中进行排序、求平均等,那么这些信息会更有用.如何将这些数据从屏幕上抓取到 CSV 文件中?>
我的第一个想法
因为我知道 jQuery,我想我可以用它来去除屏幕上的表格格式,插入逗号和换行符,然后将整个混乱复制到记事本中并另存为 CSV.有更好的想法吗?
解决方案
是的,伙计们,这真的就像复制和粘贴一样简单.我是不是觉得很傻.
具体来说,当我粘贴到电子表格时,我必须选择选择性粘贴";并选择格式文本".否则它会尝试将所有内容粘贴到单个单元格中,即使我突出显示了整个电子表格.
- 在工具的用户界面中选择 HTML 表格并将其复制到剪贴板(如果可能的话
- 将其粘贴到 Excel 中.
- 另存为 CSV 文件
然而,这是一种手动解决方案,而不是自动解决方案.
The Problem
I use a tool at work that lets me do queries and get back HTML tables of info. I do not have any kind of back-end access to it.
A lot of this info would be much more useful if I could put it into a spreadsheet for sorting, averaging, etc. How can I screen-scrape this data to a CSV file?
My First Idea
Since I know jQuery, I thought I might use it to strip out the table formatting onscreen, insert commas and line breaks, and just copy the whole mess into notepad and save as a CSV. Any better ideas?
The Solution
Yes, folks, it really was as easy as copying and pasting. Don't I feel silly.
Specifically, when I pasted into the spreadsheet, I had to select "Paste Special" and choose the format "text." Otherwise it tried to paste everything into a single cell, even if I highlighted the whole spreadsheet.
- Select the HTML table in your tools's UI and copy it into the clipboard (if that's possible
- Paste it into Excel.
- Save as CSV file
However, this is a manual solution not an automated one.
这篇关于如何将 HTML 表格抓取为 CSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!