Python程序设计作业20:crawler

2019300993-艾碧纯 2022夏-程序设计实训 2022-07-29 20:47:16
from requests_html import HTMLSession


def crawler(books=[]):
    session = HTMLSession()
    url = 'https://www.qidian.com/rank/yuepiao/'
    r = session.get(url)

    names = {}
    j = 1
    for i in range(1, 21):
        xp = f'/html/body/div[1]/div[6]/div[2]/div[2]/div/div/ul/li[{i}]/div[2]/h2/a/text()'
        name = r.html.xpath(xp)

        if name[0] in books:
            names[name[0]] = j
            j += 1

    return names


print(crawler(['光阴之外', '夜的命名术', '明克街13号']))

 

...全文
249 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

34

社区成员

发帖
与我相关
我的任务
社区描述
依托实践实训环节,为同学们更好掌握所需的基本技能,提供一个交流学习的社区。
python安全linux 高校
社区管理员
  • shawn904
  • weixin_44003872
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧