特别简单的图片爬取代码

爬取“笔趣阁官网”图片(python)
非常简单的代码

  • with open(“自己设定好的地址 + 文件名”)
  • url 那个是访问的链接
  • html.decode 其实可以不用的
from bs4 import BeautifulSoup
import requests

url = "http://www.biquge.com.tw/" 
re = requests.get(url)
html = BeautifulSoup(re.text, 'html.parser')
html.decode('utf-8')
imgs = html.find_all('img')
x = 0  # 为了对图片进行命名
for im in imgs:
    with open(r"E:\Code\Python\Project\page_get\PAGE\%s.jpg" % x, "wb") as f:
        ht = requests.get(im['src'])
        f.write(ht.content)
        x += 1
    原文作者:肥宅_Sean
    原文地址: https://www.jianshu.com/p/cff4f1b9b727
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞