文章分类 -  爬虫

爬虫学习
摘要:一。 数组要比列表效率高很多 numpy高效的处理数据,提供数组的支持,python默认没有数组。pandas、scipy、matplotlib都依赖numpy。 pandas主要用于数据挖掘,探索,分析 maiplotlib用于作图,可视化 scipy进行数值计算,如:积分,傅里叶变换,微积分 statsmodels用于统计分析 Gensim用于... 阅读全文
posted @ 2018-09-16 22:35 liang哥哥 阅读(2359) 评论(0) 推荐(1)
摘要:Python对Excel的读写主要有xlrd、xlwt、xlutils、openpyxl、xlsxwriter几种。 1.xlrd主要是用来读取excel文件 import xlrd workbook = xlrd.open_workbook(u'有趣装逼每日数据及趋势.xls') sheet_names= workbook.sheet_names() for sheet_name i... 阅读全文
posted @ 2018-09-14 14:31 liang哥哥 阅读(148) 评论(0) 推荐(0)
摘要:import random,requests,json from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.proxy import ProxyType # 设置代理... 阅读全文
posted @ 2018-09-02 15:07 liang哥哥 阅读(584) 评论(0) 推荐(0)
摘要:https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy --- numpyhttps://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy --- scipy 阅读全文
posted @ 2018-08-19 21:52 liang哥哥 阅读(115) 评论(0) 推荐(0)
摘要:import pandas as np # 依次读取多个相同结构的Excel文件并创建DataFramedfs = []for fn in ('1.xlsx', '2.xlsx', '3.xlsx', '4.xlsx'): dfs.append(pd.read_excel(fn))# 将多个DataFrame合并为一个df = pd.concat(dfs)# 写入Excel文件,不包含索引... 阅读全文
posted @ 2018-08-05 19:09 liang哥哥 阅读(5040) 评论(0) 推荐(0)
摘要:1. 简介 itchat是一个开源的微信个人号接口,使用python调用微信变得非常简单。简单是用itchat代码即可构建一个基于微信的即时通讯,更不错的体现在于方便扩展个人微信的在其他平台的更多通讯功能。 2. 安装 pip3 install itchat 3. itchat - Hellowor 阅读全文
posted @ 2018-08-02 23:09 liang哥哥 阅读(288) 评论(0) 推荐(0)
摘要:requests http请求库 requests是基于python内置的urllib3来编写的,它比urllib更加方便,特别是在添加headers, post请求,以及cookies的设置上,处理代理请求,用几句话就可以实现,而urllib比较繁琐, requests比urllib方便多了,re 阅读全文
posted @ 2018-07-14 16:42 liang哥哥 阅读(81) 评论(0) 推荐(0)
摘要:简单的项目目录结构如下: /root/test/proj/celery ├── celeryconfig.py ├── celery.py ├── __init__.py └── tasks.py 主程序celery.py #拒绝隐式引入,因为celery.py的名字和celery的包名冲突,需要使 阅读全文
posted @ 2018-07-14 13:38 liang哥哥 阅读(142) 评论(0) 推荐(0)
摘要:在编写爬虫进行网页数据的时候,大多数情况下,需要在请求是增加请求头,下面介绍一个python下非常好用的伪装请求头的库:fake-useragent,具体使用说明如下: 安装fake-useragent库 pip install fake-useragent 获取各浏览器的fake-useragen 阅读全文
posted @ 2018-07-09 09:27 liang哥哥 阅读(4208) 评论(0) 推荐(0)
摘要:import scrapy_redis import redis class FifoQueue(object): def __init__(self): self.server = redis.Redis(host='140.143.227.206',port=8888,password='beta') def push(self, request): ... 阅读全文
posted @ 2018-07-03 16:56 liang哥哥 阅读(424) 评论(0) 推荐(0)
摘要:选择器Request是一个封装用户请求的类,在回调函数中yield该对象表示继续访问HtmlXpathSelector用于结构化HTML代码并提供选择器功能from scrapy.selector import Selector, HtmlXPathSelector from scrapy.http import HtmlResponse html = """ ... 阅读全文
posted @ 2018-07-02 11:38 liang哥哥 阅读(93) 评论(0) 推荐(0)
摘要:scrapy的解析器html = """ first item first item second itemvv second item """ from scrapy.http import ... 阅读全文
posted @ 2018-07-02 11:28 liang哥哥 阅读(156) 评论(0) 推荐(0)
摘要:# twisted:基于事件循环的异步非阻塞框架,(简单的讲就是一个线程向多个目标发起http请求)# requests.get()# response.text# sk = socket.socket()# sk.setblocking(False)-socket默认是阻塞的,该设置是设置为非阻塞## twisted的执行from twisted.web.client import getPag... 阅读全文
posted @ 2018-07-02 09:25 liang哥哥 阅读(221) 评论(0) 推荐(0)
摘要:1.scrapy依赖twisted 2.twisted是什么以及和requests的区别? twisted 是基于事件循环的异步非阻塞模块或框架 封装socket发送请求,单线程完成并发请求 用来帮助我们下载页面, 内部基于事件循环的机制实现爬虫的并发 并发效率高 三个相关词 - 非阻... 阅读全文
posted @ 2018-06-29 21:14 liang哥哥 阅读(97) 评论(0) 推荐(0)
摘要:http://www.bing.com https://segmentfault.com/ https://stackoverflow.com/ 阅读全文
posted @ 2018-06-28 21:45 liang哥哥 阅读(58) 评论(0) 推荐(0)
摘要:2. scrapy genspider [-t template] <name> <domain> - 创建爬虫应用 ps:查看所有命令:scrapy gensipider -l 查看模板命令:scrapy gensipider -d 模板名称 3. scrapy list - 展示爬虫应用列表 4 阅读全文
posted @ 2018-06-27 08:45 liang哥哥 阅读(165) 评论(0) 推荐(0)
摘要:import requests from bs4 import BeautifulSoup url = 'https://github.com/login' headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.1... 阅读全文
posted @ 2018-06-26 17:45 liang哥哥 阅读(187) 评论(0) 推荐(0)
摘要:浏览器发送请求的本质:请求头,请求体请求头: 第一次发请求需要告诉服务器,请求的url和访问的浏览器BeautifulSoup会将获取到html字符串内部转换成一个html对象。find找到匹配成功的第一个,返回对象find_all 找到匹配成功的所有(子子孙孙都可以匹配),返回列表find(name='',attrs={'':''}) 建以用该方式find(name='',id='',_... 阅读全文
posted @ 2018-06-25 14:35 liang哥哥 阅读(95) 评论(0) 推荐(0)
摘要:抽屉网的爬取过程分析# ################################### 示例一:爬取数据(携带请起头) ################################### """ import requests from bs4 import BeautifulSoup r1 = requests.get( url='https://dig.chouti.c... 阅读全文
posted @ 2018-06-25 14:34 liang哥哥 阅读(156) 评论(0) 推荐(0)
摘要:scrapy框架的基本调用方式 命令行创建爬虫:scrapy startproject youyuan 命令行创建爬虫:scrapy genspider -t crawl yy 'youyuan.com' 爬虫名不能跟项目名相同 运行爬虫:scrapy crawl yy(爬虫名) 分布式爬虫运行:s 阅读全文
posted @ 2018-06-25 09:57 liang哥哥 阅读(329) 评论(0) 推荐(0)