【问题标题】:Excel - Scraping HTML Source Layout with VBAExcel - 使用 VBA 抓取 HTML 源代码布局
【发布时间】:2018-09-03 21:29:08
【问题描述】:

我有一些设计糟糕的 HTML,我试图从中抓取数据以便于阅读。

我可以使用innerHTML 获取信息,但不幸的是它显示为一堵文字墙。

当我“查看源代码”(出于隐私原因更改字词)时来自网页的源代码示例是:

<td nowrap valign="top"><b>Logger Notes</b></td>
    <td valign="top">Hi,
Person needs a full breakdown Important information.
Would also would like confirmation in a letter about what kinds of assistance 
she is not eligible for if possible.
Would prefer sent to email.
Thanks&nbsp;</td>

但是,当我得到数据时,它会显示为一堵像这样的文字墙:

Hi, Person needs a full breakdown Important information. Would also would like confirmation in a letter about what kinds of assistance  she is not eligible for if possible. Would prefer sent to email. Thanks

这显然更难阅读。

当我使用innerHTML并查看字符串时,所有换行符实际上都是空格字符,所以我不能使用replace

我已经搜索并尝试了许多不同的东西,但我无法找到一种方法来显示它以便于阅读。

该网页在我们的工作 Intranet 上,并且有一个登录(使用电子表格的多人都会使用该登录 - 所以我无法自动执行此操作)

首选输出示例:

Hi,

Person needs a full breakdown Important information.

Would also would like confirmation in a letter about what kinds of assistance she is not eligible for if possible.

Would prefer sent to email.

任何建议将不胜感激。

【问题讨论】:

  • 嗨,欢迎来到 SO!请提供一个您希望看到的输出示例(您认为它是可读的)。
  • 编辑显示首选输出
  • 在浏览器中查看源文档时,文本是否显示为您想要的输出方式?
  • 不,它显示为文字墙。(因为它没有
    等)
  • 在 html 文档的源代码中,(就像我认为的第一个框?)它是用新行等格式化的吗?

标签: vba excel


【解决方案1】:

也许,在每个句号出现后添加一个换行符?

例如,replace ".""." &amp; vbCrLf

【讨论】:

  • 这就是我要做的(目前)唯一的缺点是要求进行初始信息输入的人使用语法。 (充其量是有风险的:))
  • 您可以尝试计算字符并每隔 20-30 个左右插入一个换行符(除了在句点处换行))看起来不像来自网站的原始文本,但可能布局更好@JemSmall
猜你喜欢
  • 2021-10-10
  • 2018-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-08
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
相关资源
最近更新 更多