获取网络图片Pyhon代码

这是一个利用Python来下载网络照片的小程序,其中应用到了BeautifuSoupre正则表达式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from bs4 import BeautifulSoup as bsp
import re
import lxml
from datetime import datetime

with open(r"d:\\picurl.txt") as f:
text=f.read()
csp=bsp(text,"lxml")
print(u"已经获取地址文件,马上提取图片地址!")
d=csp.find_all('img',src=re.compile('[a-zA-z]+://[^\s]*jpg'))
for url in d:
print(url.get("src"))
with open("D:\\url.txt",'a') as f:
f.write("wget "+url.get("src")+"\n")
with open(datetime.now().date().isoformat()+'.html',"a") as f:
f.write("<img src=\""+url.get("src")+"\"><p></p>")
-------------本文结束感谢您的阅读-------------