【发布时间】: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 </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 文档的源代码中,(就像我认为的第一个框?)它是用新行等格式化的吗?