import requests import re def down_images(page=1):
# 用循环找寻前10页的图片,如果要多爬取,只需改变range后的数值即可
for page in range(1, 11):
result = requests.get('https://www.doutula.com/photo/list?page={}'.format(page)).text ''' data - original = "http://ww1.sinaimg.cn/bmiddle/9150e4e5ly1fpqcyxqu69j205b052wfa.jpg" alt = "别说了发吧" ''' reg = r'data-original="(.*?)".*?alt="(.*?)"' # S匹配多行 reg = re.compile(reg, re.S) down_images = re.findall(reg, result) # print(down_image)
#把拿到的资料保存到本地文件夹中 with open('doutula.txt', 'w+', encoding='utf-8') as f: f.write(repr(down_images)) def main(): down_images() if __name__ == '__main__': main()