| 主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情! |
| 我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作 |
原帖: https://www.hostloc.com/thread-669605-1-1.html
只爬了完本的!
估计大多数人没有yaml库 pip install pyyaml
我草 我刚才把我的账号密码写在代码里了, 虽然是测试用账号
- import requests, yaml, os, logging
- root = os.path.dirname(__file__)
- logging.basicConfig(level=logging.INFO, format=’%(asctime)s – %(levelname)s – %(message)s’)
- session = requests.session()
- def login(u, p):
- if u == R20;” or p == “”:
- print(“请填写: user pwd”)
- return
- url = f”https://www.meto3517.com/user/login?userName={u}password={p}”
- r = session.get(url).json()
- if r[“msg”] == “登錄成功”:
- print(“登陆成功”)
- else:
- print(“登陆失败!”)
- return
- def completedBooks():
- print(“获取完本ID“`”)
- url = “https://www.meto3517.com/query/books?ranking=wjbpaged=truesize=100page=1type=cartoon”
- r = session.get(url).json()
- books = r[“content”][“list”]
- return books
- def getBookChapters(id):
- url = f”https://www.meto3517.com/query/book/directory?bookId={id}”
- r = session.get(url).json()
- return r[“content”]
- def writeYamlFile(obj, bookpath):
- yamlpath = os.path.join(bookpath, “info.yaml”)
- with open(yamlpath, “w”, encoding=”utf-8″) as f:
- yaml.dump(obj, f, allow_unicode=True)
- def getImgBinaryContent(imgurl):
- r = session.get(imgurl)
- return r.content
- def downloadImgs(chapter, chapterpath):
- url = f”https://www.meto3517.com/query/book/chapter?bookId={chapter[‘bookId’]}chapterId={chapter[‘id’]}”
- r = session.get(url).json()
- imglist = r[“content”][“imageList”]
- for img in imglist:
- imgurl = img[“url”]
- imgName = img[“encodeName”].split(“_”)[0]
- imgext = img[“encodeName”].split(“.”)[-1]
- imgFullName = f”{imgName}.{imgext}”
- imgpath = os.path.join(chapterpath, imgFullName)
- with open(imgpath, “wb”) as f:
- f.write(getImgBinaryContent(imgurl))
- logging.info(f’ -> {imgFullName} ok!’)
- def downloadChapter(chapter, bookpath):
- logging.info(f’ -> {chapter[“title”]}’)
- chapterpath = os.path.join(bookpath, chapter[“title”])
- os.mkdir(chapterpath)
- downloadImgs(chapter, chapterpath)
- def downloadBook(id):
- url = f”https://www.meto3517.com/query/book?id={id}”
- r = session.get(url).json()
- logging.info(f’下载 -> {r[“content”][“name”]}’)
- obj = {}
- obj[“name”] = r[“content”][“name”]
- obj[“author”] = r[“content”][“author”]
- obj[“description”] = r[“content”][“description”]
- obj[“tags”] = r[“content”][“tags”]
- bookpath = os.path.join(root, obj[“name”])
- os.mkdir(bookpath)
- writeYamlFile(obj, bookpath)
- chapters = getBookChapters(id)
- for chapter in chapters:
- downloadChapter(chapter, bookpath)
- if __name__ == ‘__main__’:
- # 用户名 密码
- user = “”
- pwd = “”
- login(user, pwd)
- books = completedBooks()
- for book in books:
- downloadBook(book[“id”])
复制代码
燕十三丶: 等1健转存
jmmes: 大佬 你太快了
yjsx86: 带走
egihosting99: 主要是 代码一遍过, 基本没修改
Yrh: 大佬牛批,PY赛高
注册: py确实写起来比.net快好多.
注册: python3 ding.py pip3 install pyyaml 实测py2跑步起来_(:з」∠)_
这几篇文章你可能也喜欢:
- 暂无相关推荐文章
本文由主机参考刊发,转载请注明:叮咚爬虫 https://dev-web.zhujicankao.com/16615.html
主机参考














评论前必须登录!
注册