标签:www html def dal 获取网页 www. 写入 方式 find
import re
import urllib.request
# 获取网页文件
def getHtml(url):
response = urllib.request.urlopen(‘https://www.zhipin.com/?ka=header-home‘);
return response.read();
# 写入数据到文件
def writeFile(fileName,data):
# 打开文件方式为‘a‘可不覆盖原有数据
htmlFile = open(fileName, ‘a‘);
htmlFile.write(data);
htmlFile.close();
# 截取后缀为.jpg的图片
def getImgSrc(fileName):
# decode()将string转为byte
imgUrl = re.findall(r‘https:.+\.jpg‘,fileName.decode(‘utf-8‘));
return imgUrl;
html = getHtml(‘https://www.imooc.com/‘);
print(html);
imgUrl = getImgSrc(html);
for i in imgUrl:
print(i);
writeFile(‘imgUrl.txt‘, i);
标签:www html def dal 获取网页 www. 写入 方式 find
原文地址:https://www.cnblogs.com/mxh-java/p/10747808.html