鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: 二农戏猪`

[已解决]【求助】煎蛋爬妹子图程序出现不知名错误

[复制链接]
 楼主| 发表于 2020-8-11 21:55:33 | 显示全部楼层
1q23w31 发表于 2020-8-11 21:35
把写完的发一下

为什么我一发代码它就审核
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-11 21:57:49 | 显示全部楼层
二农戏猪` 发表于 2020-8-11 21:55
为什么我一发代码它就审核

不知道,审核机制搞不懂
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-11 22:09:32 | 显示全部楼层
1q23w31 发表于 2020-8-11 21:57
不知道,审核机制搞不懂

我发了个新帖
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-15 11:22:56 | 显示全部楼层    本楼为最佳答案   
本帖最后由 suchocolate 于 2020-8-15 11:53 编辑

不用xpath或bs太低效了


  1. import requests
  2. from lxml import etree
  3. import os


  4. def ck_dir():
  5.     # Please fill in the name of the path where you want to save the images
  6.     pic_dir = 'mm'
  7.     if not os.path.exists(pic_dir):
  8.         os.mkdir(pic_dir)
  9.     os.chdir(pic_dir)


  10. def get_pic_url(act_url):
  11.     r = requests.get(act_url, headers=headers)
  12.     html = etree.HTML(r.text)
  13.     # pic list
  14.     result = html.xpath('//img/@src')
  15.     # last pic is not mm pic
  16.     result.pop()
  17.     # next page url
  18.     act_nx_pg = html.xpath('//a[contains(text(),"99")]/@href')[0]
  19.     return result, act_nx_pg


  20. def main():
  21.     # pic counter
  22.     n = 1
  23.     # check pic directory
  24.     ck_dir()
  25.     # pic url list
  26.     pic_list = []
  27.     # next page url
  28.     nx_pg_url = ''
  29.     # get pics urls
  30.     for item in range(100, 98, -1):
  31.         if item == 100:
  32.             pic_url, nx_pg = get_pic_url(url)
  33.         else:
  34.             pic_url, nx_pg = get_pic_url(nx_pg_url)
  35.         nx_pg_url = f'{url}/{nx_pg}#comments'
  36.         pic_list.extend(pic_url)
  37.     # download pics
  38.     for item in pic_list:
  39.         r = requests.get('http:' + item, headers=headers)
  40.         pic_name = item.split('/')[-1]
  41.         with open(pic_name, 'wb') as f:
  42.             f.write(r.content)
  43.             print(f'{pic_name} has been downloaded. total number: {n}')
  44.             n = n + 1


  45. if __name__ == '__main__':
  46.     # global variables
  47.     url = 'http://jandan.net/ooxx'
  48.     headers = {'User-agent': 'firefox'}
  49.     # main func
  50.     main()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-25 17:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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