deepfacelab中文网

 找回密码
 立即注册(仅限QQ邮箱)
查看: 991|回复: 8

src收集爬虫

[复制链接]

6

主题

76

帖子

3653

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
3653

万事如意节日勋章

发表于 2021-10-17 15:08:20 | 显示全部楼层 |阅读模式
星级打分
  • 1
  • 2
  • 3
  • 4
  • 5
平均分:NAN  参与人数:0  我的评分:未评
本帖最后由 sdfhj 于 2021-10-18 19:04 编辑

为收集src,写了些爬虫,从网上爬写真图片。python写的,保存为.py文件使用。不知道为啥,代码里的“+”号没了。。请大家注意用的时候加一下
堆糖爬虫(爬柳岩):
  1. from urllib import request, parse
  2. import json
  3. import jsonpath
  4. import requests
  5. import os
  6. import re

  7. def mkdir(path):
  8.     # 判断是否存在文件夹如果不存在则创建为文件夹
  9.     # 如果路径不存在会创建这个路径
  10.     folder = os.path.exists(path)
  11.     if not folder:
  12.         os.makedirs(path)

  13. def DuiTang(word, num, local_path):
  14.     url_head = 'https://www.duitang.com/napi/blog/list/by_search/?kw='
  15.     form = parse.quote(word)
  16.     headers = {'User-Agent':'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
  17.     for page in range(1,int(num)):
  18.         response = request.Request(url = url_head+form+'&type=feed&include_fields=top_comments,is_root,source_link,item,buyable,root_id,status,like_count,like_id,sender,album,reply_count,favorite_blog_id&_type=&start='+str(page*24)+'&_='+str(1540109911555+page), headers=headers)

  19.         response = request.urlopen(response)
  20.         html = response.read()
  21.         unicodestr = json.loads(html)
  22.         url_list = jsonpath.jsonpath(unicodestr, "$..path")
  23.         for li in url_list:
  24.             print('\n')
  25.             print(li)
  26.             name = li.split('/')[-1]
  27.             try:
  28.                 filename = local_path + '/' + name
  29.                 if not os.path.isfile(filename):
  30.                     document = requests.get(url=li, headers=headers)
  31.                     with open(filename, 'wb') as f:
  32.                         f.write(document.content)
  33.                         print('已下载完成')
  34.                 else:
  35.                     print('已存在')
  36.             except Exception:
  37.                     print('下载失败并忽略')
  38.                     pass



  39. if __name__ == '__main__':
  40.     word = '柳岩'
  41.     num = 200
  42.     local_path = "D:\\Another\\temp\\ANOTHER_RUBBISH\\VIDEOS\\DFL_Src\\duitang\" + word
  43.     mkdir(local_path)
  44.     DuiTang(word, num, local_path)
复制代码
回车桌面爬虫(爬范冰冰):
  1. import requests
  2. import re
  3. import os
  4. from lxml import etree
  5. from faker import Faker
  6. faker = Faker(locale='zh_CN')


  7. def mkdir(path):
  8.     folder = os.path.exists(path)
  9.     if not folder:
  10.         os.makedirs(path)

  11. def get(url):
  12.     header = {'User-Agent': faker.user_agent()}
  13.     i = 0
  14.     while i < 1:
  15.         try:
  16.             result = requests.get(url, headers=header, timeout=10)
  17.             return result
  18.         except requests.exceptions.RequestException:
  19.             # print("Time out " + str(i+1))
  20.             i += 1

  21. word = '范冰冰'

  22. local_path = "D:\\Another\\temp\\ANOTHER_RUBBISH\\VIDEOS\\DFL_Src\\huiche\" + word
  23. mkdir(local_path)
  24. url = 'https://www.enterdesk.com/search/1-0-6-0-0-0/' + word

  25. while True:
  26.     print(url)
  27.     response = get(url)
  28.     get_urls = etree.HTML(response.text).xpath('//dl[@class="egeli_pic_dl"]/dd/a/@href')
  29.     if len(get_urls) == 0:
  30.         break
  31.     if get_urls is None:
  32.         break
  33.     for get_url in get_urls:
  34.         print(get_url)
  35.         response = get(get_url)
  36.         imgs = etree.HTML(response.text).xpath('/html/body/div[10]/div[1]/div[4]/div/div[1]/div/a/@src')
  37.         img_single = etree.HTML(response.text).xpath('/html/body/div[10]/div[1]/div[2]/img/@src')
  38.         if len(img_single) == 1:
  39.             imgs.append(img_single[0])
  40.         for img in imgs:
  41.             print(img)
  42.             name = img.split('/')[-1]
  43.             try:
  44.                 filename = local_path + '/' + name
  45.                 if not os.path.isfile(filename):
  46.                     document = get(img)
  47.                     with open(filename, 'wb') as f:
  48.                         f.write(document.content)
  49.                         print('已下载完成')
  50.                 else:
  51.                     print('已存在')
  52.             except Exception:
  53.                     print('下载失败并忽略')
  54.                     pass
  55.     page_num = re.search('search/(.*)-0-6-0-0-0/', url).group(1)
  56.     new_page_num = int(page_num) + 1
  57.     url = url.replace('search/' + str(page_num) + '-0-6-0-0-0/', 'search/' + str(new_page_num) + '-0-6-0-0-0/')

  58.    
复制代码




回复

使用道具 举报

3

主题

635

帖子

3877

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
3877
发表于 2021-10-17 17:15:12 | 显示全部楼层
感谢分享
回复

使用道具 举报

11

主题

305

帖子

3324

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
3324
发表于 2021-10-17 17:16:06 | 显示全部楼层
这个怎么用哦?
回复 支持 反对

使用道具 举报

10

主题

2836

帖子

1万

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
17198

万事如意节日勋章

发表于 2021-10-17 17:25:57 | 显示全部楼层
这个怎么用
回复 支持 反对

使用道具 举报

3

主题

523

帖子

4231

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
4231

万事如意节日勋章

发表于 2021-10-17 19:02:12 | 显示全部楼层
用了一下,不过估计爬出来不是原图?对画质没有太高要求的应该用起来还不错。还有就是在帖子这儿复制的代码直接跑有几处路径、文件名等的语法错误,字符串相加(合并)少了个+号,不知道是我python的版本或者编译器不一样的缘故,反正加上就能用啦,换人爬直接改代码里的名字就行。
回复 支持 反对

使用道具 举报

4

主题

346

帖子

2570

积分

初级丹圣

Rank: 8Rank: 8

积分
2570
发表于 2021-10-17 20:43:47 | 显示全部楼层
感谢分享
回复

使用道具 举报

9

主题

800

帖子

4265

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
4265
发表于 2021-10-17 20:49:36 | 显示全部楼层
谢谢楼主,是保存为bat用吗
回复 支持 反对

使用道具 举报

0

主题

1684

帖子

1万

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
11003

万事如意节日勋章

发表于 2021-10-17 22:47:35 | 显示全部楼层
感谢分享~~
回复

使用道具 举报

21

主题

256

帖子

3556

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
3556

万事如意节日勋章

QQ
发表于 2023-7-22 08:22:09 | 显示全部楼层
爬出来是原图嘛!
回复 支持 反对

使用道具 举报

QQ|Archiver|手机版|deepfacelab中文网 |网站地图

GMT+8, 2024-9-20 07:52 , Processed in 0.115001 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表