利用python爬取甲骨文图片及其对应的汉字含义,共1062个甲骨文,百度云下载

由于对古典文化较感兴趣,因此爬取甲骨文图片,及其对应的中文含义,因为网页是分目录的,因此分目录爬取。

数据来源网址:
http://www.9610.com/jiagu/bian/index.htm,
在这里插入图片描述
爬取所用代码:

import urllib.request
import re
import os
import urllib


def get_html(url):
    page = urllib.request.urlopen(url)
    html_a = page.read()

    print(html_a.decode('gbk'))
    return html_a.decode('gbk')


def get_img(html):
    reg = r'\b\d+\b.jpg'
    reg1=r'<IMG[^>]*>(.*)</TD>'
    imgre = re.compile(reg)  # 转换成一个正则对象
    imglist = imgre.findall(html)  # 表示在整个网页过滤出所有图片的地址,放在imgList中
    imgre1 = re.compile(reg1)  # 转换成一个正则对象
    imglist1 = imgre1.findall(html)  # 表示在整个网页过滤出所有图片的地址,放在imgList中
    print(imglist)
    print(imglist1)
    x = 0        # 声明一个变量赋值
    path = 'E:\\lianxi\\mypic\\y_z'  # 设置图片的保存地址
    if not os.path.isdir(path):
        os.makedirs(path)  # 判断没有此路径则创建
    paths = path + '\\'  # 保存在test路径下
    for imgurl in imglist:
        urllib.request.urlretrieve("http://www.9610.com/jiagu/bian/"+imgurl, '{0}{1}.jpg'.format(paths, str(x)+imglist1[x]))  # 打开imgList,下载图片到本地
        x = x + 1
        print('图片开始下载,注意查看文件夹')
    return imglist


html_b = get_html("http://www.9610.com/jiagu/bian/yz.htm#y")  # 获取该网页的详细信息
print(get_img(html_b))  # 从网页源代码中分析下载保存图片

爬取结果如下:
在这里插入图片描述

所有结果打包下载地址:
链接:https://pan.baidu.com/s/1IZR9tKkESY6vNbEzrbHRRQ
提取码:1tj9

欢迎下载使用,可在自建网站中作为素材使用…

  • 5
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
您可以使用Python中的第三方库来百度上的苹果图片数据。以下是一种可能的实现方式: 1. 首先,您需要安装`requests`库和`beautifulsoup4`库。您可以使用以下命令来安装它们: ``` pip install requests pip install beautifulsoup4 ``` 2. 导入所需的库: ```python import requests from bs4 import BeautifulSoup import os ``` 3. 定义一个函数来图片: ```python def download_images(keyword, num_images): url = f"https://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word={keyword}&ct=201326592&v=flip" response = requests.get(url) soup = BeautifulSoup(response.content, "html.parser") img_tags = soup.find_all("img", class_="main_img img-hover") # 创建一个目录来保存图片 os.makedirs(keyword, exist_ok=True) count = 0 for img_tag in img_tags: if count == num_images: break img_url = img_tag["src"] try: # 下载图片 response = requests.get(img_url) with open(f"{keyword}/{count+1}.jpg", "wb") as f: f.write(response.content) count += 1 print(f"Downloaded image {count}/{num_images}") except: print(f"Failed to download image {count+1}") ``` 4. 调用函数并指定关键词和要下载图片数量: ```python keyword = "苹果" # 搜索的关键词 num_images = 10 # 要下载图片数量 download_images(keyword, num_images) ``` 这样,您就可以使用Python百度上的苹果图片数据并保存在指定目录中。请注意,网站数据时要遵守相关网站的使用政策和法律法规。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值