天堂图片
#1.导包 import requests,os from lxml import etree from urllib.request import urlretrieve from urllib.parse import urljoin import zmail import zipfile headers = { 'User-Agent':'Mozilla/5.0 (windows NT 6.1; Win64; x64) APPleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' } #2.获取网页源码 url = 'http://www.ivsky.com/tupian/' response = requests.get(url,headers = headers) html_content = response.content #3.解析大分类标题和地址 root = etree.HTML(html_content) big_hrefs = root.xpath('//ul[@class="tpmenu"]/li/a/@href')#标签后面属性的值 big_titles = root.xpath('//ul[@class="tpmenu"]/li/a/text()') for big_title,big_href in zip(big_titles,big_hrefs): os.makedirs(f'天堂图片/{big_title}',exist_ok=True) big_href = urljoin(url,big_href) response = requests.get(big_href,headers = headers) html_content = response.content root = etree.HTML(html_content) small_hrefs = root.xpath('//p[@class="sline"]/p/a/@href') small_titles = root.xpath('//p[@class="sline"]/p/a/text()') for small_href,small_title in zip(small_hrefs,small_titles): os.makedirs(f'天堂图片/{big_title}/{small_title}',exist_ok=True) small_href = urljoin(url,small_href) response = requests.get(small_href,headers = headers) html_content = response.content root = etree.HTML(html_content) img_srcs = root.xpath("//ul[@class = 'pli']/li/p/a/img/@src") for src in img_srcs: urlretrieve(src,f'天堂图片/{big_title}/{small_title}/'+src.split('/')[-1]) # high_src = src.replace('/t/', '/pre/') # urlretrieve(high_src, f'天堂图片网/{big_title}/{small_title}/' + 'big_' + high_src.split('/')[-1])
相关阅读
之前写过的项目里面多数用的都是TP自带验证码类,今天没事的时候就看了一下比较流行的滑动验证。效果如下,使用的是极验提供的SDK,
可牛影像多图拼贴效果该怎么制作呢?我们可以使用可牛影像中自带的拼图效果来实现,下面我们就来看看详细的教程。1、首先启动可牛影
A5创业网(公众号:iadmin5)2月21日消息,近日网传称微信朋友圈将增加访客记录功能,对此腾讯微信团队回应称:别慌,这张图假的。最近在网络
"美女"站的发展提高了许多男性的需求,美女图片站的发展也相当的突飞猛进,例如:美女之家 以前的发展,也有相当高的流量而现在的美女站
图片SEO是网站内容优化重要的一个元素,但经常被站长所忽略,随着百度图腾的上线,图片版权的保护,将为站长提供更多的潜在流量。那么,百