Python-爬虫小计
# -*-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-爬虫小计的更多相关文章
- 一个python爬虫小程序
起因 深夜忽然想下载一点电子书来扩充一下kindle,就想起来python学得太浅,什么“装饰器”啊.“多线程”啊都没有学到. 想到廖雪峰大神的python教程很经典.很著名.就想找找有木有pdf版的 ...
- 适合新手的Python爬虫小程序
介绍:此程序是使用python做的一个爬虫小程序 爬取了python百度百科中的部分内容,因为这个demo是根据网站中的静态结构爬取的,所以如果百度百科词条的html结构发生变化 需要修改部分内容. ...
- python爬虫小实例
1.python爬取贴吧壁纸 1.1.获取整个页面数据 #coding=utf-8 import urllib def getHtml(url): page = urllib.urlopen(url) ...
- 找python爬虫小项目?github给你准备好了!
前言 即使我们都是程序员,但我们也并非都会修电脑,都会做酷炫的ppt,都会优化系统卡顿.其实程序员也是分行业.分专业的,就像医生也分内外科.呼吸科.神经科神的. 作为非专业的python选手,或者非专 ...
- Python爬虫小实践:爬取任意CSDN博客所有文章的文字内容(或可改写为保存其他的元素),间接增加博客访问量
Python并不是我的主业,当初学Python主要是为了学爬虫,以为自己觉得能够从网上爬东西是一件非常神奇又是一件非常有用的事情,因为我们可以获取一些方面的数据或者其他的东西,反正各有用处. 这两天闲 ...
- Python爬虫小实践:寻找失踪人口,爬取失踪儿童信息并写成csv文件,方便存入数据库
前两天有人私信我,让我爬这个网站,http://bbs.baobeihuijia.com/forum-191-1.html上的失踪儿童信息,准备根据失踪儿童的失踪时的地理位置来更好的寻找失踪儿童,这种 ...
- 4.Python爬虫小案例
1.网络爬虫定义:按照一定的规则,自动的抓取网站信息的程序或者脚本. 2.流程:request打开url得到html文档==浏览器打开源码分析元素节点==通过BeautifulSoup得到想要的数据= ...
- Python学习小计
1.初学Python最好选择2.7版本,因为大部分Python书籍的示例代码是基于这个版本的 2.Python安装可以参考百度经验完成 如果在电脑上同时安装2个版本,则CMD启动时只需要: py -2 ...
- python 爬虫小案例
爬取百度贴吧帖子信息 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: imcati import requests,re,time cl ...
- python爬虫小项目实战
随机推荐
- 常见的浏览器兼容性问题与解决方案——CSS篇
1.不同的浏览器的标签默认的外补丁和内补丁不同 问题症状:随便写几个标签,不加样式控制的情况下,各自的margin和padding差异较大. 碰到频率:100% 解决方案:初始化CSS的默认样式,*{ ...
- 故障排除:无法启动、访问或连接到 Azure 虚拟机上运行的应用程序
有多种原因可导致无法启用或连接到在 Azure 虚拟机 (VM) 上运行的应用程序.原因包括应用程序未在预期端口上运行或侦听.侦听端口受到阻止,或网络规则未将流量正确传递到应用程序.本文说明有条理地找 ...
- GPDB 5.x PSQL Quick Reference
General \copyright show PostgreSQL usage and distribution terms \g [FILE] or ; execute query (and se ...
- QT样式
最近在写QT的UI 分享一个助手网页 http://doc.qt.io/qt-4.8/stylesheet-examples.html
- January 28 2017 Week 4 Saturday
Do what you say, say what you do. 做你说过的,说你能做的. Do more than what you say, and sometimes say more tha ...
- python功能代码块记录
python Autopep8——按PEP8风格自动排版Python代码(参考链接) autopep8 --in-place --aggressive --aggressive test_autope ...
- 使用 JDK XML 和 java对象相互转换
Unmarshaller 类能将 XML 数据转换为 Java 内容对象. Marshaller 类能够将 Java 对象转换回 XML 数据. package jaxb; /** * Created ...
- HandyJSON代码阅读
功能:model = modelType.transform(rawdata) 使用分析: 使用机制:继承+实现配置+使用: 需要自己实现什么? 设计分析: 工具模块?机制模块?model基类? 生成 ...
- HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others) M ...
- 洛谷p1064 金明的预算方法
有附带条件的01背包 要那附件必须拿主件 因为一个主件最多有两个附件,所以每次遇到主件可能有四种选择 1.只拿主件 2.拿主件和一号附件 3.拿主件和二号附件 4.都拿 #include <cs ...