爬取妹子图

这是之前写的一个简单爬取妹纸图的爬虫,下面是源代码:

# -*- coding: utf-8 -*-

import requests,time,urllib.request,os

from multiprocessing import Process
from lxml import etree

#os.chdir("meizhu")切换工作目录
print (os.getcwd())#查看当前工作目录

headers = {"User-Agent" : "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;"}

def use_proxy():
proxy = urllib.request.ProxyHandler({‘http‘:‘proxy_addr‘})
opener = urllib.request.build_opener(proxy,urllib.request.HTTPHandler)\

def respon(imgurl):

req = urllib.request.Request(imgurl,headers=headers)
html = urllib.request.urlopen(req)
response=html.read().decode(‘utf-8‘)
#print(response)
selector = etree.HTML(str(response))

imgs =selector.xpath(‘//div[@class="pic"]/ul/li/a/img/@src‘)

for imgname in imgs:
imgnames = str(imgname.split(‘/‘)[5].split(‘.‘)[0] + ".jpg")
#print(imgnames)

file = urllib.request.urlretrieve(str(imgname), filename=imgnames)
print("爬取妹子图完成!!!!哈哈哈")

if __name__=="__main__":
for i in range(1,100):
imgurl = ‘http://www.mmjpg.com/home/‘+str(i)
respon(imgurl)

时间: 2024-08-12 02:47:42

爬取妹子图的相关文章

Python 爬虫入门(二)——爬取妹子图

Python 爬虫入门 听说你写代码没动力?本文就给你动力,爬取妹子图.如果这也没动力那就没救了. GitHub 地址: https://github.com/injetlee/Python/blob/master/%E7%88%AC%E8%99%AB%E9%9B%86%E5%90%88/meizitu.py 公众号:[智能制造专栏].欢迎关注,分享智能制造与编程那些事. 爬虫成果 当你运行代码后,文件夹就会越来越多,如果爬完的话会有2000多个文件夹,20000多张图片.不过会很耗时间,可以在

Python 爬虫入门之爬取妹子图

Python 爬虫入门之爬取妹子图 来源:李英杰  链接: https://segmentfault.com/a/1190000015798452 听说你写代码没动力?本文就给你动力,爬取妹子图.如果这也没动力那就没救了. GitHub 地址: https://github.com/injetlee/Python/blob/master/%E7%88%AC%E8%99%AB%E9%9B%86%E5%90%88/meizitu.py 爬虫成果 当你运行代码后,文件夹就会越来越多,如果爬完的话会有2

爬取妹子图(requests + BeautifulSoup)

---恢复内容开始--- 刚刚入门爬虫,今天先对于单个图集进行爬取,过几天再进行翻页爬取. 使用requests库和BeautifulSoup库 目标网站:妹子图 今天是对于单个图集的爬取,就选择一个进行爬取,我选择的链接为:http://www.mzitu.com/123114 首先网站的分析,该网站有一定的反爬虫策略,所以应对就是加入headers(目前是小白,目前不知道具体为毛这样做) Hostreferer = { 'User-Agent':'Mozilla/4.0 (compatibl

使用request+Beautiful爬取妹子图

一.request安装 pip install requests request使用示例 import requests response = requests.get('https://www.mzitu.com/') # get()方法发送请求,获取HTML网页 response.status_code # 返回状态码 response.text #以文本格式返回网页内容 response.content # 以二进制形式返回 二.BeautifulSoup库 BeautifulSoup是P

Python又来爬取妹子图啦,一个T的硬盘都不够用

淘女郎爬虫,可动态抓取淘女郎的信息和照片. 需要额外安装的第三方库 requests pip install requests pymongo pip install pymongo 学习Python过程中会遇到很多问题,你可以到我们的 python学习交流群[七 三 五,九 三 四,八 四 一],基础,进阶.从企业招聘人才需求 到怎么学习python,和学习什么内容都有免费系统分享,让你无论是自学还是找相应的培训都能让你少走弯路.希望可以帮助你快速了解Python,学习python 模块功能

python 爬取妹子图

作为一个python还没入门的小白,搞懂这段代码实在是很不容易,还要去学html的知识(#黑脸) 因此我加上了注释,比较好读懂点 #coding=utf-8 import time import requests from bs4 import BeautifulSoup import os import sys if(os.name == 'nt'): print(u'你正在使用win平台') else: print(u'你正在使用linux平台') header = {'User-Agent

aiohttp aiofiles asyncio异步爬取妹子图

import aiohttp import asyncio import aiofiles import async_timeout from bs4 import BeautifulSoup import time import os async def aitaotu(sem, urllist):     headers = {         'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/web

抓取妹子图

import requests from bs4 import BeautifulSoup import os class mzitu(): def requst(self,url):#定义获取网页的函数 headers={'user-agent':"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"}#模拟浏览器,以

Python爬虫之爬取煎蛋网妹子图

这篇文章通过简单的Python爬虫(未使用框架,仅供娱乐)获取并下载煎蛋网妹子图指定页面或全部图片,并将图片下载到磁盘. 首先导入模块:urllib.request.re.os import urllib.request import re import os urllib.request模块用于获取HTML页面数据 re模块用于通过正则表达式解析并截取HTML页面图片url os模块用于文件夹相关操作 代码不多,直接贴出来,代码解释在注释中: def crawl_jiandan(page, p