# -*-coding:utf8-*-
import requests
from bs4 import BeautifulSoup
import time
import os
import urllib
import re
import json requests.packages.urllib3.disable_warnings() headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
}
proxies = {"http": "**********************",
"https": "********************8"}
def get_bs(url):
res = requests.get(url, proxies=proxies,headers=headers,verify=False)
bs = BeautifulSoup(res.content, 'lxml')
return bs def get_first_url():
first_url_list = []
page = 1
for i in range(page):
root_url = "https://www.model61.com/mold.php?page={}".format(str(i+1))
bs = get_bs(root_url)
for i in bs.select("dt a"):
src = i.get('href')
if "php" in src:
first_url = "https://www.model61.com/{}".format(src)
first_url_list.append(first_url)
return first_url_list def get_second_url(first_url):
data = {}
bs = get_bs(first_url)
for i in bs.select(".cont-top a"):
src = i.get('href')
if "album_s" in src:
second_url = "https://www.model61.com/{}".format(src)
#print("second_url",second_url)
data["second_url"] = second_url for j in bs.select(".content_center_date"):
data["identity"] = j.get_text()
return data def get_thred_url(second_url):
bs = get_bs(second_url)
for i in bs.select("dt a"):
src = i.get('href')
if "album_list" in src:
thred_url = "https://www.model61.com/{}".format(src)
#print("thred_url", thred_url)
return thred_url def get_image_list(thred_url):
image_list = []
bs = get_bs(thred_url)
for i in bs.select(".album_list_left a")+bs.select(".album_list_right a"):
src = i.get('href')
image_path = "https://www.model61.com/{}".format(src)
image_list.append(image_path)
#print("image_path",image_path)
return image_list def download_image(image_path,image_url):
try:
r = requests.get(image_url, proxies=proxies, headers=headers, verify=False, allow_redirects=False)
with open(image_path, 'wb') as f:
f.write(r.content)
except Exception as e:
print(e) def create_face_id(data):
save_path = r""
identity = data["identity"]
ld_list = identity.split("\n")
identity = ld_list[1] + '_' + ld_list[3][4:] + "_" + ld_list[7][6:] + '_' + ld_list[8][4:]
print(identity)
identity_path = os.path.join(save_path, identity)
if not os.path.exists(identity_path):
os.mkdir(identity_path)
for image_url in data['image_list']:
image_path = os.path.join(identity_path, '{}.jpg'.format(str(int(time.time() * 1000))))
download_image(image_path, image_url) if __name__ == '__main__': first_url_list = get_first_url()
for first_url in first_url_list:
try:
data = get_second_url(first_url)
print(data)
second_url = data['second_url']
thred_url = get_thred_url(second_url)
image_list = get_image_list(thred_url)
data["image_list"] = image_list
create_face_id(data)
except Exception as e:
print(first_url,e)

Python-爬虫小计的更多相关文章

  1. 一个python爬虫小程序

    起因 深夜忽然想下载一点电子书来扩充一下kindle,就想起来python学得太浅,什么“装饰器”啊.“多线程”啊都没有学到. 想到廖雪峰大神的python教程很经典.很著名.就想找找有木有pdf版的 ...

  2. 适合新手的Python爬虫小程序

    介绍:此程序是使用python做的一个爬虫小程序  爬取了python百度百科中的部分内容,因为这个demo是根据网站中的静态结构爬取的,所以如果百度百科词条的html结构发生变化 需要修改部分内容. ...

  3. python爬虫小实例

    1.python爬取贴吧壁纸 1.1.获取整个页面数据 #coding=utf-8 import urllib def getHtml(url): page = urllib.urlopen(url) ...

  4. 找python爬虫小项目?github给你准备好了!

    前言 即使我们都是程序员,但我们也并非都会修电脑,都会做酷炫的ppt,都会优化系统卡顿.其实程序员也是分行业.分专业的,就像医生也分内外科.呼吸科.神经科神的. 作为非专业的python选手,或者非专 ...

  5. Python爬虫小实践:爬取任意CSDN博客所有文章的文字内容(或可改写为保存其他的元素),间接增加博客访问量

    Python并不是我的主业,当初学Python主要是为了学爬虫,以为自己觉得能够从网上爬东西是一件非常神奇又是一件非常有用的事情,因为我们可以获取一些方面的数据或者其他的东西,反正各有用处. 这两天闲 ...

  6. Python爬虫小实践:寻找失踪人口,爬取失踪儿童信息并写成csv文件,方便存入数据库

    前两天有人私信我,让我爬这个网站,http://bbs.baobeihuijia.com/forum-191-1.html上的失踪儿童信息,准备根据失踪儿童的失踪时的地理位置来更好的寻找失踪儿童,这种 ...

  7. 4.Python爬虫小案例

    1.网络爬虫定义:按照一定的规则,自动的抓取网站信息的程序或者脚本. 2.流程:request打开url得到html文档==浏览器打开源码分析元素节点==通过BeautifulSoup得到想要的数据= ...

  8. Python学习小计

    1.初学Python最好选择2.7版本,因为大部分Python书籍的示例代码是基于这个版本的 2.Python安装可以参考百度经验完成 如果在电脑上同时安装2个版本,则CMD启动时只需要: py -2 ...

  9. python 爬虫小案例

    爬取百度贴吧帖子信息 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: imcati import requests,re,time cl ...

  10. python爬虫小项目实战

随机推荐

  1. ado.net c#基本的增加,修改,删除,查询

    自己初次学习用的,各种不规范,注释没写 class AdoDemo { static string strConn = @"Data Source=server1;Initial Catal ...

  2. PHP 调用web service接口(.net开发的接口)

    实例代码1: try { $this->soapClientObj = new SoapClient(self::URL . '?wsdl', array('connection_timeout ...

  3. mac和windows自动清理内存工具

    因为我比较懒,所以需要一款能自动清理电脑内存的工具,目的是设置内存最小值,然后自动清理. mac: drcleaner windows: MaxMem win10设置开机启动地址:C:\Program ...

  4. Day04——Python模块

    一.模块简介 模块是实现了某个功能的代码集合,比如几个.py文件可以组成代码集合即模块.其中常见的模块有os模块(系统相关),file模块(文件操作相关) 模块主要分三类: 自定义模块 :所谓自定义模 ...

  5. backtrack渗透测试中常用的命令总结

    ping 域名/ip 测试本机到远端主机是否联通. dig 域名/ip 查看域名解析的详细信息. host -l 域名 dns服务器 传输zone. 扫描 nmap: -sS 半开扫描TCP和SYN扫 ...

  6. Core Animation 与 GPU

    https://en.wikipedia.org/wiki/Core_Animation#cite_note-apptech-1 Core Animation provides a way for d ...

  7. BZOJ2346:[Baltic 2011]Lamp(最短路)

    Description 2255是一个傻X,他连自己家灯不亮了都不知道. 某天TZ大神路过他家,发现了这一情况, 于是TZ开始行侠仗义了. TZ发现是电路板的问题, 他打开了电路板,发现线路根本没有连 ...

  8. springboot+mybatis+shiro——登录认证和权限控制

    转载:https://z77z.oschina.io/ 一.引入依赖 shiro-all包含shiro所有的包.shiro-core是核心包.shiro-web是与web整合.shiro-spring ...

  9. EasyUI使用之鼠标双击事件

    easyui鼠标双击事件,使用 onDblClickRow(index, row) 事件,在用户双击一行的时候触发,参数包括: index:点击的行的索引值,该索引值从0开始. row:对应于点击行的 ...

  10. caffe 学习(3)——Layer Catalogue

    layer是建模和计算的基本单元. caffe的目录包含各种state-of-the-art model的layers. 为了创建一个caffe model,我们需要定义模型架构在一个protocol ...