python连接redis并插入url
#!/usr/bin/env python
# -*- coding:utf8 -*- import redis '''
这种连接是连接一次就断了,耗资源.端口默认6379,就不用写
r = redis.Redis(host='127.0.0.1',port=6379,password='tianxuroot')
r.set('name','root') print(r.get('name').decode('utf8'))
'''
'''
连接池:
当程序创建数据源实例时,系统会一次性创建多个数据库连接,并把这些数据库连接保存在连接池中,当程序需要进行数据库访问时,
无需重新新建数据库连接,而是从连接池中取出一个空闲的数据库连接
'''
pool = redis.ConnectionPool(host='127.0.0.1',password='helloworld') #实现一个连接池 r = redis.Redis(connection_pool=pool)
r.set('foo','bar')
print(r.get('foo').decode('utf8'))
from bs4 import BeautifulSoup
import requests
from lxml import etree
import redis pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
r = redis.Redis(connection_pool=pool)
# r = Redis.from_url("redis://127.0.0.1:6379", decode_responses=True) def get_urls(url):
result = requests.get(url)
selector = etree.HTML(result.text)
links = selector.xpath(r'//*[@id="archive"]/div/div[2]/p[1]/a[1]/@href')
for link in links:
r.sadd("first_urlsss", link)
next_url = extract_next_url(result.text)
if next_url:
get_urls(next_url) def extract_next_url(html): soup = BeautifulSoup(html, "lxml")
next_url = soup.select('a[class="next page-numbers"]')
for url in next_url: url = str(url)
soup = BeautifulSoup(url, "lxml")
next_url = soup.a["href"]
return next_url if __name__ == '__main__':
url = "http://python.jobbole.com/all-posts/"
get_urls(url)
python连接redis并插入url的更多相关文章
- python连接redis、redis字符串操作、hash操作、列表操作、其他通用操作、管道、django中使用redis
今日内容概要 python连接redis redis字符串操作 redis之hash操作 redis之列表操作 redis其他 通用操作,管道 django中使用redis 内容详细 1.python ...
- python连接redis,redis集群
python连接redis: import redis r = redis.Redis(host='192.168.50.181',port=6002) r.set('user_phone_14900 ...
- python 连接 redis cluster 集群
一. redis集群模式有多种, cluster模式只是其中的一种实现方式, 其原理请自行谷歌或者百度, 这里只举例如何使用Python操作 redis cluster 集群 二. python 连接 ...
- python连接redis哨兵集群
一.redis集群模式有多种, 哨兵模式只是其中的一种实现方式, 其原理请自行谷歌或者百度 二.python 连接 redis 哨兵集群 1. 安装redis包 pip install redis 2 ...
- redis基础之python连接redis(五)
前言 前面介绍了在数据库命令行直接操作redis,现在学习使用python的redis包来操作redis,本人安装的是redis==2.10.6: 系列文章 redis安装和配置 redis命令行操作 ...
- Python连接Redis连接配置
1. 测试连接: Python 2.7.8 (default, Oct 20 2014, 15:05:19) [GCC 4.9.1] on linux2 Type "help", ...
- python连接redis sentinel集群
安装 python redis 客户端 pip install redis #!/usr/bin/env python # -*- coding:utf-8 -*- #!/usr/bin/env py ...
- Python连接redis时要注意的点
一.一般连接redis情况 from redis import Redis # 实例化redis对象 rdb = Redis(host='localhost', port=6379, db=0) rd ...
- python连接redis
一.首先,要下载redis pip3 install redis 二.连接redis import redis #拿到一个redis的链接 conn=redis.Redis('127.0.0.1',6 ...
随机推荐
- 3 Suggested Oracle Certifications For Oracle Form's Developers
The following are the most suggested Oracle Certifications for Oracle Application Developers in Form ...
- 在红米note4上实现自动安装软件
因为要做自动化测试,需要对已发布的包进行回归手测,这个时候需要手动安装APK,但是红米会弹出继续安装的按钮,手点一次比较烦,想自动点"继续安装"按钮! 感谢先行者们的分享 本文参考 ...
- VS2010 MFC中 在FormView派生类里获取文档类指针的方法
经过苦苦调试,今晚终于解决了一个大问题. 我想要实现的是:在一个FormView的派生类里获取到文档类的指针. 但是出现问题:试了很多办法,始终无法获取到. 终于,此问题在我不懈地调试加尝试下解决了. ...
- Centos7/RedHat7 下 python3使用cx-freeze打包matplotlib程序遇到的问题和解决办法
折腾了一天遇到了几个头疼的问题,还好回去前解决掉了 第一个:执行cxfreeze打包好的程序遇到 tkinter 和 _tkinter的缺失问题 首先终端:python tkinter python ...
- maven module和project的区别
Maven Project可以理解为父工程.Maven Module可以理解为子工程.创建Maven Module工程必须有存在的父工程,maven就是通过父子工程进行工程管理的.
- 在cmd窗口输入命令遇到You must run this command from a command prompt with administrator privilege怎么办?
点开始菜单,找到Accessories(附件),找到Command Prompt窗口,点右键,选“run as administrator”(以管理员身份运行),之后再执行先前的命令就好了. 2017 ...
- suid sgid sbit chattr lsattr find
suid 一般用于二进制可执行文件不可用于shell脚本和目录,suid代表当用户执行此二进制文件时,暂时具有此文件所有者的权限 chmod 4xxx binfile sgid 一般用于目录,sgid ...
- jsp中jquery用法一步刷新 验证用户名是否存在
<script type="text/javascript"> /* $(document).ready(function(){ var id="ha&quo ...
- quartz 应用到 spring定时任务 执行两次
https://my.oschina.net/superkangning/blog/467487
- iOS 一些struct类型的NSLog输出
我们经常会输出一些坐标尺寸信息之类的,比如view的frame,是CGRect类型的,用frame.oringial.x 和frame.size.width来做NSLog参数好麻烦,还好苹果对这些常用 ...