爬取校花网

一、 爬取校花网

import re
import requests

"""
@author RansySun
@create 2019-07-22-16:04
"""
# 请求地址
response = requests.get('http://www.xiaohuar.com/huar')
data = response.text
count = 0
# <img width="210" alt="" src="/d/file/20190709/small5f7964a2667ca292b77aed06cd3546341562683536.jpg">
# 查找链接地址
data_res = re.findall('src="(.*?)"', data)

for result in data_res:  # type:str

    if result.startswith("/d"):
        result = f"http://www.xiaohuar.com"+result
        img_rsponse = requests.get(result)
        img_name = result.split("/")[-1]
        img_data = img_rsponse.content
        fw = open(f"{count}_{img_name}", "wb")
        fw.write(img_data)
        count += 1
        fw.flush()
        print(f"爬取{count}张图片")


校花网

posted @ 2019-07-23 14:49  RandySun  阅读(242)  评论(0编辑  收藏  举报