特别简单的图片爬取代码

作者: 肥宅_Sean | 来源:发表于2018-01-11 22:46 被阅读45次

爬取“笔趣阁官网”图片(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

相关文章

网友评论

    本文标题:特别简单的图片爬取代码

    本文链接:https://www.haomeiwen.com/subject/njqxoxtx.html