python 爬虫图片

import requests

.img='img.png'

.files={'img':('test.png',open(img,'rb'),'image/png')}

sdata={'username':username,'content':cont}

res=requests.post(url,data=sdata,files=files)

print res.text



ls=requests.get(url)

f=open("1.png",'wb')

f.write(f)

f.flush()

f.close()


#!/usr/bin/python

#coding=utf-8

import MySQLdb  

self.conn = MySQLdb.connect(host='localhost',user='',passwd='',db='0')

cursor = self.conn.cursor()

cursor.execute( "INSERT INTO Dem_Picture (PicData) VALUES (%s)" , (MySQLdb.Binary(b)))

# self.conn.commit()

# 读取表内图片数据,并写入硬盘文件

cursor.execute( "SELECT PicData FROM Dem_Picture ORDER BY ID DESC limit 1" )

d = cursor.fetchone()[0]

cursor.close()

f = open( "C:\\22.jpg" , "wb" )

f.write(d)

f.close()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容