新手今天刚学python~~~ 有点凌乱~勉强看吧 只能算是给新手看看,见谅

简单版本的 豆瓣采集美图~~~~~~ 美女天天有 有木有~~~

python 3.4

sqlite3

BeautifulSoup 4.4

 from bs4 import BeautifulSoup
import urllib.request
import time,sched,os
import sqlite3
import sys #sys.exit() cx = sqlite3.connect('c:\\sqlite\\test.db')
global cu
cu=cx.cursor()
cu.execute('select name from sqlite_master where type=\'table\' order by name;')
for ds in cu.fetchall():
#print(ds[0])
if ds[0] != 'caiji':
print("表不存在,开始创建")
cu.execute("create table caiji (id INTEGER PRIMARY KEY AUTOINCREMENT,pid integer,nickname text NULL); ")
else:
print("存在")
break
#t=('grmlmgjsadf',)
#cx.execute("insert into caiji(nickname) values(?)",t)
#cx.commit()
#cu.execute('select * from caiji where nickname=\''+'grmlmgjsadf'+'\'')
#if cu.fetchall():
# print('dsa') #cu.close()
#cx.close() path="d:\\imgs\\"
ISOTIMEFORMAT='%Y%m%d' def dwonloadimg(uri):
temp=time.strftime(ISOTIMEFORMAT, time.localtime())
isexists=os.path.exists(path+temp)
if not isexists:
os.makedirs(path+temp)
conn=urllib.request.urlopen(uri)
pos=uri.rfind("/")
name=uri[pos+1:]
f=open(path+temp+'\\'+name,'wb')
f.write(conn.read())
conn.close()
f.close() def Getarticle1(uri):
res=urllib.request.urlopen(uri)
html=res.read()
res.close()
str(html,'utf-8')
bs=BeautifulSoup(html)
imgs=bs.find_all('div',class_="topic-figure cc")
for s in imgs:
strc=s.find('img').attrs['src']
print('图片:',strc)
dwonloadimg(strc)
def init():
print('开始抓取')
url="http://www.douban.com/group/haixiuzu/"
temp=urllib.request.urlopen(url)
html=temp.read()
str(html,'utf-8')
bs=BeautifulSoup(html)
divs=bs.find_all('td',class_='title')
for s in divs:
uri=s.a["href"]
#print(s.a.string,"\n",uri)
cu.execute('select * from caiji where nickname=\''+uri+'\'')
global cu
if not cu.fetchall():
print("新文章")
cx.execute("insert into caiji(nickname) values(?)",(uri,))
cx.commit()
Getarticle1(uri)
# else:
# print("文章存在")
print("结束") while True:
init()
time.sleep(60)

最新文章

  1. 时间--cd //lastyear
  2. Quartz.net(调度框架) 使用Mysql作为存储
  3. Popmotion – 小巧,灵活的 JavaScript 运动引擎
  4. 解决点击状态栏时ScrollView自动滚动到初始位置失效办法
  5. S5PV2210
  6. C#基础|初探反射
  7. apache 实用配置
  8. 转 Oracle全文检索http://docs.oracle.com/cd/E11882_01/text.112/e24436/toc.htm
  9. Gradle方式构建Java多项目
  10. linux 如何禁用账号和解除禁用账号
  11. HTML+CSS笔记 CSS进阶续集
  12. WINCE下进程间通信(二)
  13. Match类解析
  14. http,socks4,socks5代理的区别
  15. 批量处理word所有回车行
  16. Git上传空文件夹
  17. 大数据时代的Python金融应用-Day1-Python与金融应用概述
  18. MB_SELECT_GR_BLOCKED_STOCK 读取物料收货冻结库存
  19. 牛x的JavaScript编辑器你知道几个
  20. go语言之进阶篇非结构体匿名字段

热门文章

  1. 021_mac提效神奇Alfred
  2. springcloud-1: 用官方的pom.xml配置添加依赖失败
  3. 【原创】运维基础之Docker(6)性能
  4. [转]GitHub上优秀的Go开源项目
  5. 新手-ios
  6. linux学习之软件包安装
  7. liunx 利用nginx 实现负载均衡
  8. 信息摘要算法之四:SHA512算法分析与实现
  9. Vue.extend和Vue.component的联系与差异
  10. 【python】获取http响应