gpt4 book ai didi

python - 如何转换html链接?

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:27 27 4
gpt4 key购买 nike

假设我下载了很多html页面到目录

/path/to/my/dir

.html 页面包含如下链接:

"<a href="http://www.example.com/lessons/firstlesson.htm">first lesson</a>"

"<a href="http://www.example.com/lessons/secondlesson.htm">second lesson</a>"

感谢 TobSpr ,答案将它们转换如下:

"<a href="/path/to/my/dir/firstlesson.htm">first lesson</a>"

"<a href="/path/to/my/dir/secondlesson.htm">second lesson</a>"

更新

但是如何处理这种格式的链接: “第一课”

"<a href="../index.htm">index</a>"

使用通常的字符串函数非常困难、肮脏且有错误,所以我希望得到另一种更好的方法。

最佳答案

content.replace("http://www.example.com/", "file///path/to/dir/")

它还替换了包含路径。

关于python - 如何转换html链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17770826/

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