• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python血脉贲张的cosplay小姐姐图片

python 搞java代码 3年前 (2022-05-21) 12次浏览 已收录 0个评论

前言

本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。

基本环境配置

相关模块pip安装即可

确定目标网页

分析网页

1、查看图片地址

代码实现

<code class="language-python">import requests
import parsel
<a href="https://www.gaodaima.com/tag/url" title="查看更多关于url的文章" target="_blank">url</a> = "https://bcy.net/coser/toppost100"
response = requests.get(url=url, headers=headers)
<a href="https://www.gaodaima.com/tag/selector" title="查看更多关于selector的文章" target="_blank">selector</a> = parsel.Selector(response.text)
urls = selector.css(".rank-index-box .rank-cos-top img::attr(src)").getall()
titles = selector.css(".rank-index-box .rank-cos-avatar-box p::text").getall()
lis = zip(urls, titles)
for i in lis:
    img_url = i[0]
    title = i[1]
    response_2 = requests.get(url=img_url, headers=headers)
    path = "D:pythondemocos小姐姐img" + title + ".jpg"
    with open(path, mode="wb") as f:
        f.write(response_2.content)
        print(img_url)
</code>

www#gaodaima.com来源gaodaimacom搞#^代%!码网搞代码

图片数据是爬取下来了,但是保存数据后发现,仅仅只有20张图片,这根本不是我想要的~

所以要重新分析网页了~看一下是否有接口数据

我清空所有加载出来的数据,下拉的时候,然后出现一个神秘地址,点击去一看,果然是接口数据。为了保证准确性,咱们可以多往下翻翻

果然~~~

通过链接对比,发现接口数据的参数P是改变的,等同于页数编码,1就是对应的前20张图片数据

代码实现

<code class="language-python">import requests
for page in range(1, 6):
    url = "https://bcy.net/apiv3/rank/list/itemInfo"
    params = {
        "p": "{}".format(page),
        "ttype": "cos",
        "sub_type": "week",
        "date": "20200922",
        "_signature": "a2ovWQAAAAAem6QHkeiiVmtqL0AADQG",
    }

    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
    }
    """
    Json 接口数据
    """
    response = requests.get(url=url, params=params, headers=headers)
    html_data = response.json()
    info_list = html_data["data"]["top_list_item_info"]
    for i in info_list:
        img_url = i["item_detail"]["cover"]
        title = img_url.split("/")[-1].split("~")[0]
        response_2 = requests.get(url=img_url, headers=headers)

        path = "D:pythondemocos小姐姐img" + title + ".jpg"
        with open(path, mode="wb") as f:
            f.write(response_2.content)
            print(img_url)
</code>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python血脉贲张的cosplay小姐姐图片

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址