我想对一个表进行解析,并通过J汤-Java下载它。我知道我可以为此使用函数getElementById
。我现在的问题是:如何在网站的html代码中找到这个id?作为一个例子,我将给出这维基百科文章中的第一个表格。
发布于 2020-04-06 02:28:58
也许这个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“的文件,其中包含表。
https://stackoverflow.com/questions/61057191
复制