爬虫过程中获取不到列表页的url
摘要:例1: 采集某网站的时候根据网页页面显示的url链接提取的, 最后始终没有数据返回。 主要原因是页面源码中标签的 href 属性值和页面上的不一样。 页面上显示是‘http://www.xxx.org.cn/crs/xhjj/index.jhtml’ 源码中显示是‘http://www.xxx.or
阅读全文
posted @
2019-07-25 14:09
KD_131
阅读(977)
推荐(0)
xpath提取标签和内容
摘要:转:https://segmentfault.com/q/1010000012110138/a-1020000012113020 如何把table标签提取出来,结果如下: 代码如下:
阅读全文
posted @
2019-07-22 14:07
KD_131
阅读(3447)
推荐(0)
redis作为消息队列的原理
摘要:<!-- flowchart 箭头图标 勿删 --> Redis队列功能介绍 List 转:https://blog.csdn.net/cestlavieqiang/article/details/84197736 常用命令: Blpop删除,并获得该列表中的第一元素,或阻塞,直到有一个可用 Brp
阅读全文
posted @
2019-07-22 09:31
KD_131
阅读(3989)
推荐(0)
redis实现数据库(一)
摘要:转:https://www.cnblogs.com/beiluowuzheng/p/9738159.html 服务器中的数据库 Redis服务器将所有数据库都保存在服务器状态redis.h/redisServer结构体的db数组中,db数组的每个项都是一个redis.h/redisDb结构体,每个r
阅读全文
posted @
2019-07-21 11:15
KD_131
阅读(643)
推荐(0)
给插入的数据去重
摘要:import random # 对插入的数据 去重 lst = [] for k in range(20): i = random.randint(1,10) print(i) if i not in lst: lst.append(i) print(lst)
阅读全文
posted @
2019-07-19 17:10
KD_131
阅读(297)
推荐(0)
selenium 操作 获取动态页面数据
摘要:# selenium from selenium import webdriver import time driver_path = r"G:\Crawler and Data\chromedriver.exe" driver = webdriver.Chrome(executable_path=driver_path) driver.get('https://www.baidu.com/...
阅读全文
posted @
2019-07-16 07:19
KD_131
阅读(7648)
推荐(0)
selenium 爬boss
摘要:# 有问题 from selenium import webdriver import time from lxml import etree class LagouSpider(object): driver_path = r"G:\Crawler and Data\chromedriver.exe" def __init__(self): self....
阅读全文
posted @
2019-07-16 07:13
KD_131
阅读(454)
推荐(0)
selenium (四) WebDriverWait 与 expected_conditions
摘要:在介绍WebDriverWait之前,先说一下,在selenium中的两种等待页面加载的方式,第一种是隐式等待,在webdriver里面提供的implicitly_wait()方法,driver.implicitly_wait(30) #单位:秒第二种是显示等待,是在support/wait中的We
阅读全文
posted @
2019-07-15 15:53
KD_131
阅读(396)
推荐(0)
requests.exceptions.SSLError报错
摘要:requests.exceptions.SSLError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'
阅读全文
posted @
2019-07-12 18:55
KD_131
阅读(5237)
推荐(1)
mysql去除重复数据
摘要:转: https://www.cnblogs.com/qlqwjy/p/8270011.html 今天一个同学问我mysql去除重复数据,自己做了个测试顺便记录下: 查看表结构: mysql> desc testdelete; + + + + + + + | Field | Type | Null
阅读全文
posted @
2019-07-08 15:19
KD_131
阅读(774)
推荐(0)
navicat中查重并删除
摘要:# 查询所有重复的数据 SELECT * FROM hao123 WHERE ir_url IN (SELECT ir_url FROM `hao123` GROUP BY ir_url having count(ir_url)>1) # 只显示某几个字段 提高查询速度SELECT ir_title,ir_url FROM hao123 WHERE ir_url IN(SELECT ir_ur...
阅读全文
posted @
2019-07-08 15:06
KD_131
阅读(2291)
推荐(0)
生成随机字符串
摘要:python生成随机数、随机字符串 import randomimport string # 随机整数:print random.randint(1,50) # 随机选取0到100间的偶数:print random.randrange(0, 101, 2) # 随机浮点数:print random.
阅读全文
posted @
2019-07-07 20:52
KD_131
阅读(621)
推荐(0)
数据库基本操作
摘要:表的操作 1.创建表 实例: 2.查询表的数据和结构 3.复制表 4.删除表 drop table 表名;
阅读全文
posted @
2019-07-07 20:19
KD_131
阅读(225)
推荐(0)
爬取链家网租房图 使用ImagesPipeline保存图片
摘要:# 爬虫文件 # -*- coding: utf-8 -*- import scrapy import os from urllib import request from lianjia.items import LianjiaItem class LianjiaspiderSpider(scrapy.Spider): name = 'lianjiaSpider' # all...
阅读全文
posted @
2019-07-06 17:58
KD_131
阅读(816)
推荐(0)
os.path.join路径拼接的问题
摘要:问题一: import os a = os.path.join("/test1", "/test2") print(a) b = os.path.join("/test1", "test2") print(b) import os a = os.path.join("/test1", "/test2
阅读全文
posted @
2019-07-06 17:54
KD_131
阅读(1390)
推荐(0)
os.path.dirname(__file__)
摘要:os.path.dirname(__file__) 返回脚本的路径 描述: 必须实际存在的.py文件,如果直接在命令行执行,则会引发异常NameError: name 'file' is not defined; 在运行的时候如果输入完整的执行路径,则返回.py文件的全路径如:/Users/goka
阅读全文
posted @
2019-07-04 22:20
KD_131
阅读(259)
推荐(0)
ConnectionPool实现redis在python中的连接
摘要:这篇文章主要介绍了Python与Redis的连接教程,Redis是一个高性能的基于内存的数据库,需要的朋友可以参考下 今天在写zabbix storm job监控脚本的时候用到了python的redis模块,之前也有用过,但是没有过多的了解,今天看了下相关的api和源码,看到有ConnectionP
阅读全文
posted @
2019-07-03 17:24
KD_131
阅读(6470)
推荐(0)
RedisCrawlSpider
摘要:这个RedisCrawlSpider类爬虫继承了RedisCrawlSpider,能够支持分布式的抓取。因为采用的是crawlSpider,所以需要遵守Rule规则,以及callback不能写parse()方法。 同样也不再有start_urls了,取而代之的是redis_key,scrapy-re
阅读全文
posted @
2019-07-03 17:15
KD_131
阅读(341)
推荐(0)
scrapy 发post请求
摘要:可以使用 yield scrapy.FormRequest(url, formdata, callback)方法发送POST请求。 如果希望程序执行一开始就发送POST请求,可以重写Spider类的start_requests(self) 方法,并且不再调用start_urls里的url。 clas
阅读全文
posted @
2019-07-03 16:19
KD_131
阅读(196)
推荐(0)
django项目分解
摘要:https://www.cnblogs.com/huwei934/tag/django/
阅读全文
posted @
2019-07-03 16:14
KD_131
阅读(111)
推荐(0)
os.path.join用法
摘要:os.path.join()函数:连接两个或更多的路径名组件 1.如果各组件名首字母不包含’/’,则函数会自动加上 2.如果有一个组件是一个绝对路径,则在它之前的所有组件均会被舍弃 3.如果最后一个组件为空,则生成的路径以一个’/’分隔符结尾 Demo1 import os Path1 = 'hom
阅读全文
posted @
2019-07-03 16:05
KD_131
阅读(726)
推荐(0)
图片懒加载,Selenium,PhantomJS
摘要:引入 今日概要 图片懒加载 selenium phantomJs 谷歌无头浏览器 知识点回顾 验证码处理流程 今日详情 动态数据加载处理 一.图片懒加载 什么是图片懒加载? 案例分析:抓取站长素材http://sc.chinaz.com/中的图片数据 #!/usr/bin/env python #
阅读全文
posted @
2019-07-03 10:57
KD_131
阅读(337)
推荐(0)
js动态生成数据的抓取
摘要:需求:爬取https://www.xuexi.cn/f997e76a890b0e5a053c57b19f468436/018d244441062d8916dd472a4c6a0a0b.html页面中的新闻数据。 分析: 1.首先通过分析页面会发现该页面中的新闻数据都是动态加载出来的,并且通过抓包工具
阅读全文
posted @
2019-07-03 10:53
KD_131
阅读(822)
推荐(0)
cur.execute(sql,args)和cur.execute(sql)的区别
摘要:轉:https://blog.csdn.net/mjjyszazc/article/details/88932664 方式一: userid = “123”sql = “select id,name from user where id = ‘%s’” % useridcur.execute(sql
阅读全文
posted @
2019-07-03 10:04
KD_131
阅读(1540)
推荐(0)
中国天气网数据获取
摘要:# 中国天气网 # 练习使用 BeautifulSoup 解析 # 数据可视化 import requests from bs4 import BeautifulSoup import html5lib from pyecharts import Bar ALL_DATA = [] def parse_page(url): headers = { "User-...
阅读全文
posted @
2019-07-02 23:11
KD_131
阅读(2103)
推荐(0)
爬虫下载中间件
摘要:# 设置随机请求头 设置代理ip # 在middleware.py文件中 写一个类 class MiddlewearproDownloaderMiddleware(object): user_agent_list = [ "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 " "(KHTML,...
阅读全文
posted @
2019-07-02 23:03
KD_131
阅读(292)
推荐(0)
简书全站CrawlSpider爬取 mysql异步保存
摘要:# 简书网 # 数据保存在mysql中; 将selenium+chromedriver集成到scrapy; 整个网站数据爬取 # 抓取ajax数据 #爬虫文件 # -*- coding: utf-8 -*- import scrapy from scrapy.linkextractors impor
阅读全文
posted @
2019-07-02 23:01
KD_131
阅读(427)
推荐(0)
房天下新房和二手房
摘要:# 爬虫文件 # -*- coding: utf-8 -*- import scrapy import re from soufangwang.items import NewHouseItem,SecondhandHouseItem class FangspiderSpider(scrapy.Spider): name = 'fangSpider' allowed_doma...
阅读全文
posted @
2019-07-02 22:59
KD_131
阅读(396)
推荐(0)
多线程
摘要:# 图片 下载耗时 用多线程 # threading模块 import threading import time def coding(): for i in range(3): print("正在写代码%s"%i) time.sleep(1) def drawing(): for i in range(3): print(...
阅读全文
posted @
2019-07-02 22:57
KD_131
阅读(211)
推荐(0)
selenium+chromdriver 动态网页的爬虫
摘要:# 获取加载更多的数据有 2 种方法# 第一种就是直接找数据接口, 点击'加载更多' 在Network看下, 直接找到数据接口 # 第二种方法就是使用selenium+chromdriver
阅读全文
posted @
2019-07-02 22:53
KD_131
阅读(634)
推荐(0)
汽车之家下载文件和图片
摘要:# scrapy框架里下载问价和图片 # 判断文件夹和路径是否存在 # 爬虫文件 import scrapy from bmw.items import BmwItem class Bme5Spider(scrapy.Spider): name = 'bme5' allowed_domains = ['car.autohome.com.cn'] start_urls ...
阅读全文
posted @
2019-07-02 22:49
KD_131
阅读(937)
推荐(0)
re正则
摘要:#转义字符和原生字符 import re # # # 转义 # text = 'apple price is $299' # ret = re.search('\$\d+',text) # print(ret.group()) # # 原生字符串 text = '\c' ret = re.match('\\\\c',text) print(ret.group()) # group 分组 ...
阅读全文
posted @
2019-07-02 22:46
KD_131
阅读(404)
推荐(0)
糗图多线程
摘要:# qiutu 多线程 from lxml import etree import requests import os from urllib import request import threading from queue import Queue class Producer(threading.Thread): headers = { "User-Ag...
阅读全文
posted @
2019-07-02 22:43
KD_131
阅读(159)
推荐(0)
mongodb数据存储
摘要:# 打开服务端 直接执行abc.bat文件,如果执行闪退可以把data文件夹里的mongod.lock文件先删除 打开cmd窗口, 输入mongo,启动客户端. 也可以通过NoSQLBooster启动客户端 # mongodb 部分基本操作命令 db: 查看当前的数据库 show dbs: 查看所有数据库 use 数据库名:切换数据库 db.dropDatabase():删除当前指...
阅读全文
posted @
2019-07-02 22:42
KD_131
阅读(369)
推荐(0)
雪球美股
摘要:import requests import csv from pyecharts import Bar url = 'https://xueqiu.com/hq?page=1#exchange=US&firstName=3&secondName=3_0' headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebK...
阅读全文
posted @
2019-07-02 22:36
KD_131
阅读(549)
推荐(0)
多线程爬虫
摘要:threading模块 condition的生产者消费者模式 lock版的生产者消费者模式 queue的线程安全 threading类实现多线程 selenium关闭页面和浏览器 selenium页面等待 selenium打开多个页面和页面间的切换 多线程共享全局变量 selenium设置代理ip
阅读全文
posted @
2019-07-02 22:27
KD_131
阅读(298)
推荐(0)
安装mysql时出现应用程序无法正常启动(0xc000007b)、初始化失败以及密码忘记怎样重置?
摘要:https://blog.csdn.net/zztingfeng/article/details/80155624
阅读全文
posted @
2019-07-02 10:10
KD_131
阅读(811)
推荐(0)
mysql 安装使用
摘要:本节掌握内容: MySQL的介绍安装、启动 windows上制作服务 MySQL破解密码 MySQL中统一字符编码 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司。MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好
阅读全文
posted @
2019-07-02 10:09
KD_131
阅读(228)
推荐(0)