VPS参考测评推荐
专注分享VPS主机优惠信息
衡天云优惠活动
热网互联2026年促销活动
hostkvm优惠促销活动
zji优惠促销活动

叮咚爬虫

主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

原帖: https://www.hostloc.com/thread-669605-1-1.html
只爬了完本!
估计大多数人没yaml库 pip install pyyaml
我草 我刚才把我的账号密码写在代码里了, 虽然测试用账号

  1. import requests, yaml, os, logging
  2. root = os.path.dirname(__file__)
  3. logging.basicConfig(level=logging.INFO, format=’%(asctime)s – %(levelname)s – %(message)s’)
  4. session = requests.session()
  5. def login(u, p):
  6.     if u == R20;” or p == “”:
  7.         print(“请填写: user pwd”)
  8.         return
  9.     url = f”https://www.meto3517.com/user/login?userName={u}password={p}”
  10.     r = session.get(url).json()
  11.     if r[“msg”] == “登錄成功”:
  12.         print(“登陆成功”)
  13.     else:
  14.         print(“登陆失败!”)
  15.         return
  16. def completedBooks():
  17.     print(“获取完本ID“`”)
  18.     url = “https://www.meto3517.com/query/books?ranking=wjbpaged=truesize=100page=1type=cartoon”
  19.     r = session.get(url).json()
  20.     books = r[“content”][“list”]
  21.     return books
  22. def getBookChapters(id):
  23.     url = f”https://www.meto3517.com/query/book/directory?bookId={id}”
  24.     r = session.get(url).json()
  25.     return r[“content”]
  26. def writeYamlFile(obj, bookpath):
  27.     yamlpath = os.path.join(bookpath, “info.yaml”)
  28.     with open(yamlpath, “w”, encoding=”utf-8″) as f:
  29.         yaml.dump(obj, f, allow_unicode=True)
  30. def getImgBinaryContent(imgurl):
  31.     r = session.get(imgurl)
  32.     return r.content
  33. def downloadImgs(chapter, chapterpath):
  34.     url = f”https://www.meto3517.com/query/book/chapter?bookId={chapter[‘bookId’]}chapterId={chapter[‘id’]}”
  35.     r = session.get(url).json()
  36.     imglist = r[“content”][“imageList”]
  37.     for img in imglist:
  38.         imgurl = img[“url”]
  39.         imgName = img[“encodeName”].split(“_”)[0]
  40.         imgext = img[“encodeName”].split(“.”)[-1]
  41.         imgFullName = f”{imgName}.{imgext}”
  42.         imgpath = os.path.join(chapterpath, imgFullName)
  43.         with open(imgpath, “wb”) as f:
  44.             f.write(getImgBinaryContent(imgurl))
  45.         logging.info(f’    -> {imgFullName} ok!’)
  46. def downloadChapter(chapter, bookpath):
  47.     logging.info(f’    -> {chapter[“title”]}’)
  48.     chapterpath = os.path.join(bookpath, chapter[“title”])
  49.     os.mkdir(chapterpath)
  50.     downloadImgs(chapter, chapterpath)
  51. def downloadBook(id):
  52.     url = f”https://www.meto3517.com/query/book?id={id}”
  53.     r = session.get(url).json()
  54.     logging.info(f’下载 -> {r[“content”][“name”]}’)
  55.     obj = {}
  56.     obj[“name”] = r[“content”][“name”]
  57.     obj[“author”] = r[“content”][“author”]
  58.     obj[“description”] = r[“content”][“description”]
  59.     obj[“tags”] = r[“content”][“tags”]
  60.     bookpath = os.path.join(root, obj[“name”])
  61.     os.mkdir(bookpath)
  62.     writeYamlFile(obj, bookpath)
  63.     chapters = getBookChapters(id)
  64.     for chapter in chapters:
  65.         downloadChapter(chapter, bookpath)
  66. if __name__ == ‘__main__’:
  67.     # 用户名 密码
  68.     user = “”
  69.     pwd = “”
  70.     login(user, pwd)
  71.     books = completedBooks()
  72.     for book in books:
  73.         downloadBook(book[“id”])

复制代码

各路大神回复

注册感谢分享   拿走了

yjsx86: 帮顶一下  

燕十三丶: 等1健转存

b66667777: w cao 密码我

jmmes: 大佬 你太快了

yjsx86: 带走

ficefox: 拿走拿走,感谢大佬,晚不睡了

egihosting99: 主要是 代码一遍过, 基本修改

Yrh: 大佬牛批,PY赛高

注册: py确实写起来比.net快好多.

注册: python3 ding.py pip3 install pyyaml 实测py2跑步起来_(:з」∠)_

这几篇文章你可能也喜欢:

  • 暂无相关推荐文章

本文由主机参考刊发,转载请注明:叮咚爬虫 https://dev-web.zhujicankao.com/16615.html

【腾讯云】领8888元采购礼包,抢爆款云服务器 每月 9元起,个人开发者加享折上折!
打赏
转载请注明原文链接:主机参考 » 叮咚爬虫
主机参考仅做资料收集,不对商家任何信息及交易做信用担保,购买前请注意风险,有交易纠纷请自行解决!请查阅:特别声明

评论 抢沙发

评论前必须登录!