牛刀小试

Posted zqxqx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了牛刀小试相关的知识,希望对你有一定的参考价值。

目标:http://qq.yh31.com/zjbq/2920180_2.html

#!/urs/bin/evn python
# -*- coding:utf-8 -*-
import requests
import re


def get_urls(url):
    """
    获取目标url
    :param url: 
    :return: 
    """
    response = requests.get(url)
    response.encoding = "utf-8"
    ret = <img border="0".*?src="(.*?)"
    url_list = re.findall(ret, response.text)
    return url_list


def get_gif(url, name):
    """
    获取完整图片url
    :param url: 
    :param name: 
    :return: 
    """
    response_img = requests.get(url)
    response_img.encoding = "utf-8"
    with open(r"D:data\\%d.gif" % name, "wb") as ft:
        ft.write(response_img.content)

if __name__ == "__main__":
    first_url =["http://qq.yh31.com/zjbq/2920180.html", "http://qq.yh31.com/zjbq/2920180_2.html"]
    a = 1
    for url in first_url:
        url_list = get_urls(url)

        for url in url_list:
            com_url = "http://qq.yh31.com" + url # 图片路径拼接
            # print(com_url)  测试
            get_gif(com_url, a)
            a += 1
# requests.text  把我获取到requests转成 字符串
# requests.json  从requests获取json文件
# requests.content 从requests获取二进制文件

技术分享图片

以上是关于牛刀小试的主要内容,如果未能解决你的问题,请参考以下文章

Threejs系列--7游戏开发加载glb模型之牛刀小试

VSCode Snippet 小试牛刀

牛刀小试

[前端学习]从0到1做一个Vue风格的Todolist(Vue牛刀小试)

[前端学习]从0到1做一个Vue风格的Todolist(Vue牛刀小试)

小试牛刀-利用AST平坦化一段瑞数代码