一起玩python大数据 爬虫Python AI Sql程序员

特别简单的图片爬取代码

2018-01-11  本文已影响45人  肥宅_Sean

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

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
上一篇 下一篇

猜你喜欢

热点阅读