【原创】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 MySQLdb在windows环境下的安装、出错问题以及解决办法
版权声明:本文为博主原创文章,未经博主允许不得转载. 问题:windows下安装MySQLdb的方法 解析:python没有php那种集成环境,比如wamp那种集成软件直接把所有需要的东西全部一次性搭 ...
- [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 ...
随机推荐
- percona mysql5.7关闭审计功能方法
数据库的审计日志占用大量空间,当时是为了测试审计功能开启的,现在需要关闭 # /data/mysql_data]# du -sh * 124G audit.log # 查询审计相关参数 mysql&g ...
- Laravel 5.2--如何让表单提交错误,不清空?
控制器 public function store(Request $request) { $validator = Validator::make($request->all(), [ 'Su ...
- Expm 10_1 带负权值边的有向图中的最短路径问题
[问题描述] 对于一个带负权值边的有向图,实现Bellman-Ford算法,求出从指定顶点s到其余顶点的最短路径,并判断图中是否存在负环. package org.xiu68.exp.exp10; p ...
- ubuntu18.04安装xmind8
1.先去官网下载:https://www.xmind.net/download/xmind8/ 2.默认下载到/home/guojihai/下载/目录下然后把xmind-8-update8-linux ...
- tcpdump详解
tcpdump -i eth1 'host 121.14.84.221 and greater 76' -Ap -v -s10000 抓取 eth1 和 121.14.84.221 上的所有长度大于7 ...
- 43)django-用户认证,授权,自定义用户认证
##用户认证 django自带用户认证系统,包括认证和授权.用户认证系统由用户,权限,用户组,密码,cookie和session给组成. ###用户认证系统设置 #settings.py INSTAL ...
- Poco::Crypto--加解密(AES)
Poco::Crypto--加解密(AES) 1 int main(const std::vector<std::string>& args) 2 { 3 /*TO DO*/ 4 ...
- LuoGu P1083 借教室
题目传送门 借教室这个题有两种做法,差分+前缀和或者是线段树 线段树维护区间最小值,因为能不能借教室使用是由这几天中可用教室最少的一天决定的 其实这题是个很裸的线段树维护区间最小值,但有一点需要注意, ...
- flex 兼容性写法
flex http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html 阮一峰老师详解 box 用于父元素的样式: display: box; 该属 ...
- js——事件冒泡与捕获小例子
布局代码 #outer{ width: 300px; height: 300px; background: red; } #inner{ width: 200px; height: 200px; ba ...