# -*-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. android启动应用

    private void openApp(String packageName) { PackageInfo pi = getPackageManager().getPackageInfo(packa ...

  2. mongodb 3.4复制集配置

    1:启动三个实例 /bin/mongod --config /home/mongodb/db27017/mongodb27017.conf /bin/mongod --config /home/mon ...

  3. 爬虫入门之Scrapy框架实战(新浪百科豆瓣)(十二)

    一 新浪新闻爬取 1 爬取新浪新闻(全站爬取) 项目搭建与开启 scrapy startproject sina cd sina scrapy genspider mysina http://roll ...

  4. Useful WCF Behaviors - IErrorHandler

    Behaviors in WCF are so stinking useful, and once you get past the basics of WCF they're arguably a ...

  5. Json 和 Jsonlib 的使用

    什么是 Json JSON(JvaScript Object Notation)(官网网站:http://www.json.org/)是 一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解 ...

  6. CodeForces 91A Newspaper Headline

    题目链接:CodeForces - 91A  Newspaper Headline 官方题解: In this problem letters from s1 should be taken gree ...

  7. Django 导出csv文件 中文乱码问题

    import csvimport codecsimport datetimefrom django.db import connectionfrom django.contrib.auth.model ...

  8. halcon 数字转字符串实现循环读取图片

    1.将字符转换为数字 tuple_number (StringImageIndex,IntImageIndex) 2.将数字转换为字符 tuple_string (IntImageIndex, '0' ...

  9. Semi-Supervised Dimensionality Reduction

    今天阅读了一篇关于半监督降维的论文,做个总结.这篇论文的全名叫<Semi-Supervised Dimensionality Reduction>(2006),是南大周志华老师的大作. 本 ...

  10. maven学习利用Profile构建不同环境的部署包

    项目开发好以后,通常要在多个环境部署,象我们公司多达5种环境:本机环境(local).(开发小组内自测的)开发环境(dev).(提供给测试团队的)测试环境(test).预发布环境(pre).正式生产环 ...