Python 官方文档:入门教程 => 点击学习
前段时间买了个 kindle ,所以就不想老是开电脑 看 书了。而在学习python 时,看到Python 主要的还是熟悉一些库的功能。 所以就想着
下面是一段用来练手的 python 捉取html 内容的代码:
import urllib2
import os
import re
#打开并保存hmtl
def save_html(urlname):
main_url=r'Https://docs.python.org/2/library/'
main_dir=r'E:BOOKpythonpython_library'
url=main_url+urlname+'.html'
file_name=main_dir+'\' +urlname+'.html'
try:
req=urllib2.urlopen(url)
urlfile=open(file_name,'w')
urlfile.write(req.read())
except:
print url
finally:
urlfile.close()
#保存主页
save_html('index')
#正则表达式查找链接并保存对应文件
req=urllib2.urlopen(r'https://docs.python.org/2/library/index.html')
p=re.compile(r'''<li class="toctree-.+?"><a class="reference internal" href="(.+?).html">.+?</a></li>''')
matchs=p.findall(req.read())
for row in matchs:
save_html(row)
捉完后,使用了 [ calibre - E-book management ] 把html 转换成mobi 格式的文件。
mobi 下载链接:
http://f.dataguru.cn/forum.PHP?mod=attachment&aid=MTQ5OTQzfDc1Y2MyMDk5fDE0MDgxNzEzNTB8NDQxMTd8MzM3NjMy
--结束END--
本文标题: 抽取python 标准库页面生成 mob
本文链接: https://www.lsjlt.com/news/184234.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0