python 豆瓣采集
新手今天刚学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)
python 豆瓣采集的更多相关文章
- 【原创】python 豆瓣采集
新手今天刚学python~~~ 有点凌乱~勉强看吧 只能算是给新手看看,见谅 简单版本的 豆瓣采集美图~~~~~~ 美女天天有 有木有~~~ python 3.4 sqlite3 BeautifulS ...
- 13行代码实现:Python实时视频采集(附源码)
一.前言 本文是<人脸识别完整项目实战>系列博文第3部分:程序设计篇(Python版),第1节<Python实时视频采集程序设计>,本章内容系统介绍:基于Python+open ...
- python爬虫采集
python爬虫采集 最近有个项目需要采集一些网站网页,以前都是用php来做,但现在十分流行用python做采集,研究了一些做一下记录. 采集数据的根本是要获取一个网页的内容,再根据内容筛选出需要的数 ...
- [Python]豆瓣用户读书短评下载工具
简介 朋友问我能不能做一个下载他在豆瓣读书上的短评的工具,于是就做了这个“豆瓣用户读书短评下载工具”. GitHub链接:https://github.com/xiaff/dbc-downloader ...
- python 豆瓣图片的爬取
豆瓣图片的抓取:在python中实现生产者和消费者模型的实现,大家可以参考这篇文章 http://www.bkjia.com/Pythonjc/978391.html 个人认为是讲的比较易懂的,只要看 ...
- Python实现采集wordpress整站数据的爬虫
最近爱上了python,就非常喜欢使用python来练手,在上次的基础上完善一下代码,实现采集wordpress程序的网站的整站数据的爬虫程序,本站也是采用的wordpress,我就拿吾八哥网(htt ...
- Python 豆瓣源
国内的pythoner强烈建议使用豆瓣的pypi源 https://pypi.douban.com/simple/ sudo pip install -i https://pypi.douban.co ...
- [Python] 通过采集两万条数据,对《无名之辈》影评分析
一.说明 本文主要讲述采集猫眼电影用户评论进行分析,相关爬虫采集程序可以爬取多个电影评论. 运行环境:Win10/Python3.5. 分析工具:jieba.wordcloud.pyecharts.m ...
- [Python] 豆瓣电影top250爬虫
1.分析 <li><div class="item">电影信息</div></li> 每个电影信息都是同样的格式,毕竟在服务器端是用 ...
随机推荐
- Android安全专项-利用androguard分析微信
androguard Androguard经常使用API学习1 安装 做 Android 安全測试之前你应该知道的工具 (一) 分析 ./androlyze.py -s进入分析的交互界面 然后运行 a ...
- vim各种编码设置问题
vim各种编码设置问题 vim中主要有四个编码相关的设置,详细是~/.vimrc中: 下面是我的设置: set fileencodings=gb18030,utf-8,gb2312,gbk: set ...
- LINUX6安装Oracle10g无法启动安装界面解决
***********************************************声明*************************************************** ...
- path和classpath细节
从学习java的最初我们就被要求先设置path变量和classpath变量.但是这两个环境变量到底有什么作用呢? 1.path环境变量 path环境变量的主要作用是告诉操作系统到哪里去寻找某个程序,如 ...
- Spark Streaming VS Flink Streaming
引自:https://www.slideshare.net/datamantra/introduction-to-flink-streaming
- MongoDB的CURD命令
1.启动客户端 在MongDB服务成功启动的情况下,打开cmd,在MongDB的bin文件目录下执行MongDB命令 可以看到MongDB版本号3.0.7与默认连接的数据库test.test数据库是系 ...
- 【python】for循环
>>> exp='welcom to python'>>> for i in exp: print(i,end=' ') w e l c o m t o p y t ...
- 【ANT】使用ANT自动执行JMeter用例
1.把\apache-jmeter-3.1\extras目录下的build.xml和jmeter-results-detail-report_21.xsl两个文件拷贝到用例所在目录: 2.修改用例名称 ...
- Android 开发,你遇上 Emoji 头疼吗?
在 Android 中,如果需要使用的到 Emoji 表情,你会发现在某些设备上,有一些 Emoji 表情会被以豆腐块 "☐" 的形式显示,这是因为当前设备并不支持这个 Emoji ...
- oracle初级(续)
有志者.事竟成,破釜沉舟,百二秦关终属楚: 苦心人.天不负,卧薪尝胆,三千越甲可吞吴. oracle基本简单的用法,之前的笔记稍作整理一下,希望对各位有用,如有问题可在下方留言,所有SQL都是经过or ...