首页 > 编程语言 >Python学习日记 2023年8月21日

Python学习日记 2023年8月21日

时间:2023-08-21 19:04:04浏览次数:35  
标签:picture 21 title Python resp url href 2023 headers

import requests
import os
import re
from time import sleep
from bs4 import BeautifulSoup

url = 'http://www.netbian.com/mei/'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
}
resp = requests.get(url,headers=headers)
resp.encoding='gbk'
resp_html =resp.text
soup = BeautifulSoup(resp_html,'lxml')
urls_a = soup.find_all('img')
for url_a in urls_a:
    if 'small' in url_a['src']:
        picture_url = url_a['src']
        picture_title = url_a['alt']
        picture_url_list = re.split(r'(\d+)',picture_url)
        picture_url = picture_url.replace('small','')
        picture_url = picture_url.replace(picture_url_list[-2],'')
        # print(picture_title,picture_url)
        picture = requests.get(picture_url,headers=headers).content
        with open(picture_title+'.jpg','wb')as f:
            f.write(picture)
        print('图片'+picture_title+'下载完成')
    # try:
    #     href = url_a['href']
    #     title = url_a['title']
    #     if '/desk' in href:
    #         # print(url_a[1])
    #         # href_url = f'http://www.netbian.com{href}'
    #         # picture = requests.get(href_url,headers=headers).content
    #         # # print(picture)
    #         # with open(title+'.jpg','wb')as f:
    #         #     f.write(picture)       
    # except:
    #     continue

今天重新做下图片下载,明天继续

标签:picture,21,title,Python,resp,url,href,2023,headers
From: https://blog.51cto.com/u_2469839/7178335

相关文章

  • 8.21 模拟赛小记
    A.吃饭路上也要锻炼,原P3505[POI2010]TEL-Teleportation咱现在思路通了,代码实现可能得鸽一鸽。两个强强的博客:https://www.cnblogs.com/stoorz/p/12182770.html,https://www.cnblogs.com/reywmp/p/14014611.html。是很难的思维题,涉及乘法原理和图论,用到了分层思想。统计答案时......
  • Linux系统之编译安装python3
    (Linux系统之编译安装python3)一、python3介绍1.python3简介Python3是一种高级编程语言,由GuidovanRossum于2008年发布。它是Python编程语言的最新版本,是Python2的升级版本。Python3提供了很多新的功能和改进,使得程序员可以更加快速、简便地编写高质量的代码。2.python......
  • 高频SQL 50题(基础版): 学生们参加各科测试的次数 | 2023-08-21
    问题学生表:Students+---------------+---------+|ColumnName|Type|+---------------+---------+|student_id|int||student_name|varchar|+---------------+---------+在SQL中,主键为student_id(学生ID)。该表内的每一行都记录有学校一名学生......
  • 2023年免费图床有哪些?
    最近频繁使用到图床,搜集了自己使用过的比较好用的国内图床网站,有知名大站也有小众网站,使用体验都不错!1.路过图床地址:https://imgse.com/介绍:国内比较知名的图床,用户使用较多的图床工具之一,免费,但是页面有少量广告。高速稳定的图片上传和外链服务,全球CDN加速,最大单张支持1......
  • 【8月摸鱼计划】python不支持的数据类型
    python不支持的数据类型是:char、byte类型。python支持的数据类型有:文本类型:str数值类型:int,float,complex序列类型:list,tuple,range映射类型:dict集合类型:set,frozenset布尔类型:bool二进制类型:bytes,bytearray,memoryview......
  • Python学习之半角转全角
    defstrB2Q(ustring):  rstring=""  forucharinustring:    inside_code=ord(uchar)    ifinside_code==32:      inside_code=12288    elif32<=inside_code<=126:      inside_code+=65248......
  • 北大ACM poj2141 Message Decowding
    MessageDecowdingTimeLimit:1000MS MemoryLimit:65536KTotalSubmissions:10326 Accepted:5672DescriptionThecowsarethrilledbecausethey'vejustlearnedaboutencryptingmessages.Theythinktheywillbeabletousesecretmessagestoplot......
  • 《最新出炉》系列初窥篇-Python+Playwright自动化测试-12-playwright操作iframe-中篇
    1.简介按照计划今天就要用实际的例子进行iframe自动化测试。经过宏哥长时间的查找,终于找到了一个含有iframe的网页(QQ邮箱和163邮箱),别的邮箱宏哥就没有细看了。所以今天这一篇的主要内容就是用这两个网页的iframe结合上一篇的理论知识,宏哥给小伙伴或者童鞋们演示一下。2.QQ邮箱2......
  • 2023商用密码大会启幕,天翼云商用密码能力体系重磅亮相!
    8月9日,在国家密码管理局指导下,由中国密码学会作为支持单位,郑州市人民政府、河南省密码管理局主办的2023商用密码大会拉开帷幕。大会以“密码赋能美好发展”为主题,旨在推进商用密码创新驱动、前沿交流、产业对接、协同合作。作为参展企业,天翼云展示了云电脑、智能计算平台“云骁”、......
  • python判断字符串是否包含子串的五种方法
    python判断字符串是否包含子串的五种方法一、用find()方法判断要判断某一个字符串是否包含某一个子串,方法之一是可以利用python内置的字符串方法find()来查找,如果查找到,就返回子串第一个字符在原字符串中的索引位置,如果找不到,则返回-1,实例代码如下:>>>string='笨鸟工具,x1y1z1......