gpt4 book ai didi

java - 如何查找 html-table ID

转载 作者:行者123 更新时间:2023-12-01 17:35:01 25 4
gpt4 key购买 nike

我想解析一个表并通过 Jsoup-Java 下载它。我知道我可以使用函数 getElementById 来达到此目的。我现在的问题是:如何在网站的 html 代码中找到该 id?作为一个例子,我将给出 this 中的第一个表。维基百科文章。

最佳答案

也许这个Python脚本可以帮助你下载网站的源代码:

from urllib.request import urlopen

html = urlopen("https://support.image-line.com/member/profile.php?module=Unlock").read()

f = open("source.html", 'wb')
f.write(html)
f.close()

然后您还使用 python 修剪文件内容,因此删除 <tbody> 之前的内容标记并关闭它后。

示例:

with open("source.html", "r") as f:
content = f.read()
position = content.find("<tbody>")
content = content[position:]
split_string = content.split("</tbody>", 1)

substring = split_string[0]
with open("table.html", "w") as out:
out.write(substring)
out.close()
f.close()

现在您将获得一个名为“table.html”的文件,其中包含该表。

关于java - 如何查找 html-table ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61057191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com