鱼C论坛

 找回密码
 立即注册
查看: 1410|回复: 1

爬虫求助

[复制链接]
发表于 2023-9-13 17:13:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
https://baijiahao.baidu.com/s?id=1765736748275541689

像这种百家号的文章图片怎么爬取
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-9-13 17:13:49 | 显示全部楼层
您好,想要爬取这种类型的文章图片,可以使用Python的第三方库requests和BeautifulSoup来实现。具体步骤如下:

1. 使用requests库获取网页内容:
import requests

url = 'https://baijiahao.baidu.com/s?id=1765736748275541689'
response = requests.get(url)
html = response.text

2. 使用BeautifulSoup库解析网页内容,并获取图片链接:
from bs4 import BeautifulSoup

soup = BeautifulSoup(html, 'html.parser')
img_tags = soup.find_all('img')

img_urls = []
for img in img_tags:
    img_url = img.get('src')
    img_urls.append(img_url)

3. 下载图片:
import os

save_folder = 'images'
if not os.path.exists(save_folder):
    os.makedirs(save_folder)

for img_url in img_urls:
    img_name = img_url.split('/')[-1]
    img_path = os.path.join(save_folder, img_name)

    with open(img_path, 'wb') as f:
        img_data = requests.get(img_url).content
        f.write(img_data)

以上是一个简单的爬虫实现过程,但需要注意的是,爬取他人网站内容需要获得对方的授权,否则可能会侵犯对方的知识产权。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 13:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表