码迷,mamicode.com
首页 > Web开发 > 详细

使用 urllib 打开、匹配和保存远程文件

时间:2018-02-01 00:18:02      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   cas   org   pytho   retrieve   www   文件中   open   imp   

 

利用 urlretrieve 获取远程文件保存到本地

from urllib.request import urlretrieve
urlretrieve(http://www.python.org,rD:\python\python37\python_wegpage.html)

利用 urlopen 和 re 匹配获取远程文件中的数据

from urllib.request import urlopen
import re
wegpage = urlopen(http://www.python.org)
text = wegpage.read()
text = text.decode(utf-8)
m = re.search(<a href="([^"]+)" .*?>about</a>,text,re.IGNORECASE)
m.group(1)

 

使用 urllib 打开、匹配和保存远程文件

标签:style   cas   org   pytho   retrieve   www   文件中   open   imp   

原文地址:https://www.cnblogs.com/swingingmace/p/8395004.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!