【python】又拍云采集工具助手exe带python图片采集源码
论坛的老哥要的东西!练手试了一下!
技术比较渣,见谅!
拿去玩!
自己测试了一下,没有用多线程,可能速度还是比较low!
写了报错以及记录功能,如果没有下载到的图片,自己手动补上吧,失败的链接都写在spIDer.txt上!
运行测试:
exe百度云地址:
链接: https://pan.baidu.com/s/1BUo52myhLfRM22wQU2asxg 提取码: i7qd
又拍云相册图片采集助手使用说明:
1.打开yupoo.exe程序!
2.输入又拍云相册的首页地址,比如:https://chenxuezhen1989.x.yupoo.com!
3.回车运行即可!
4.采集失败链接记录在spIDer.txt,建议自行手动补图片!
附上python源码:
# -*- Coding: UTF-8 -*-import requests,re,os,random,timefrom lxml import etreeclass Yupoo(): def __init__(self,url): ua_List = [ "Mozilla/4.0 (compatible; MSIE 6.0; windows NT 5.1; SV1; Acoobrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "Mozilla/4.0 (compatible; MSIE 7.0; windows NT 6.0; Acoo browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)", "Mozilla/4.0 (compatible; MSIE 7.0; Aol 9.5; AolBuild 4337.35; windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "Mozilla/5.0 (windows; U; MSIE 9.0; windows NT 9.0; en-US)", "Mozilla/5.0 (compatible; MSIE 9.0; windows NT 6.1; Win64; x64; TrIDent/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)", "Mozilla/5.0 (compatible; MSIE 8.0; windows NT 6.0; TrIDent/4.0; WOW64; TrIDent/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)", "Mozilla/4.0 (compatible; MSIE 7.0b; windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)", "Mozilla/5.0 (windows; U; windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)", "Mozilla/5.0 (X11; U; linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6", "Mozilla/5.0 (windows; U; windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1", "Mozilla/5.0 (windows; U; windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 firefox/3.0 KAPIko/3.0", "Mozilla/5.0 (X11; linux i686; U;) Gecko/20070322 Kazehakase/0.4.5", "Mozilla/5.0 (X11; U; linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6", "Mozilla/5.0 (windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20", "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52", ] self.ua=random.choice(ua_List) self.url=url #抓取首页相册分类链接 def get_categoryList(self): headers={'user-agent': self.ua} ceagortyLists=[] response=requests.get(self.url,headers=headers,timeout=5).text time.sleep(1) req=etree.HTML(response) ceagortyList=req.xpath('//div[@]/a/@href') for List in ceagortyList: List=f'{url}{List}' ceagortyLists.append(List) print(ceagortyLists) return ceagortyLists #抓取相册所有链接 def get_urlList(self,ceagortyLists): headers = {'user-agent': self.ua} category_Lists=[] for url in ceagortyLists: response = requests.get(url,headers=headers,timeout=5).text time.sleep(1) req = etree.HTML(response) category_urlLists=req.xpath('//div[@]/a[@]/@href') for category_url in category_urlLists: category_url=f'{self.url}{category_url}' category_Lists.append(category_url) print(category_Lists) return category_Lists #采集图片 def get_img(self,url): headers = {'user-agent': self.ua} response = requests.get(url,headers=headers,timeout=5).text time.sleep(1) req = etree.HTML(response) h2=req.xpath('//h2/span[@]/text()')[0] h2= re.sub(r'[\|\/\<\>\:\*\?\\"]', "_", h2) # 剔除不合法字符 print(h2) os.makedirs(f'yupoo/{h2}/',exist_ok=True) imgurls=req.xpath('//div[@]/div[@]/img/@data-origin-src') i=1 headers2 = { 'referer': url, 'user-agent': self.ua, } print(headers) for imgurl in imgurls: imgurl=f'https:{imgurl}' print(imgurl) if "jpeg" in imgurl: imgname=f'{i}{imgurl[-5:]}' elif "jgp" in imgurl or "png" in imgurl or "gif" in imgurl: imgname = f'{i}{imgurl[-4:]}' else: imgname = f'{i}{imgurl[-4:]}' print(imgname) try: r=requests.get(imgurl,headers=headers2,timeout=8) with open(f'yupoo/{h2}/{imgname}','wb') as f: f.write(r.content) print(f'下载{imgname}图片成功!') time.sleep(1) except Exception as e: print(f'下载{imgurl}图片失败,错误代码:{e}') with open(f'yupoo/{h2}/spIDer.txt','a+',enCoding='utf-8') as f: f.write(f'访问相册{url}---{imgurl}---下载失败,错误代码:{e}') i=i+1if __name__ == '__main__': #url="https://chenxuezhen1989.x.yupoo.com" url=input("请输入要爬取的又拍相册首页链接地址:") print(f'爬虫启动中,请稍后......') spIDer=Yupoo(url) print(f'相册首页分类链接采集中,请稍后......') ceagortyLists=spIDer.get_categoryList() print(f'相册首页分类链接采集完毕!') time.sleep(2) print(f'相册所有链接采集中,时间可能稍长,请稍后......') category_Lists=spIDer.get_urlList(ceagortyLists) print(f'相册所有链接采集完毕!') print(f'正在采集相册图片......') for url in category_Lists: try: spIDer.get_img(url) print(f'恭喜!采集{url}网页图片成功!') except Exception as e: print(f'采集网页图片失败,错误代码:{e}') with open(f'yupoo/spIDer.txt', 'a+', enCoding='utf-8') as f: f.write(f'{url}---采集失败,错误代码:{e}') print(f'采集完毕,采集{url}图片成功!') print(f'10后自动结束程序,退出!') time.sleep(10)
总结 以上是内存溢出为你收集整理的【python】又拍云采集工具助手exe带python图片采集源码全部内容,希望文章能够帮你解决【python】又拍云采集工具助手exe带python图片采集源码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)