摘要: 安装Splash(拉取镜像下来)docker pull scrapinghub/splash安装scrapy-splashpip install scrapy-splash启动容器docker run -p 8050:8050 scrapinghub/splashsetting 里面配置SPLASH 阅读全文
posted @ 2017-12-11 20:05 窃语 阅读(3708) 评论(0) 推荐(0) 编辑
摘要: # 把所有类别的前3页的小说爬取下来 import scrapyfrom scrapy.http import Requestfrom time import sleepfrom qidianNovel.spiders.connectionSQL import getredis,getMongodb 阅读全文
posted @ 2017-12-06 21:11 窃语 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 总的来说起点小说还是挺好爬的,就是爬取小说的时候太慢了,4000多本小说就爬了2天一夜 首先爬取的是网页的所有类别,并把类别名存入到mongodb中,链接存到redis中: 阅读全文
posted @ 2017-12-05 20:33 窃语 阅读(252) 评论(0) 推荐(0) 编辑
摘要: 先介绍下我自己爬起点小说的思路: 1.爬取所有的类型列表 a.链接存redis中 类型表:novel_list 具体每一种类型:bnovel_all_list(把novel_list和bnovel_list合并为bnovel_list) b.名字存到mongodb中,构成树链表 表名: bnovel 阅读全文
posted @ 2017-12-04 21:54 窃语 阅读(239) 评论(0) 推荐(0) 编辑
摘要: import scrapyfrom scrapy.http import Requestfrom scrapy.spider import Rulefrom scrapy.linkextractors import LinkExtractor# yield 就是return返回的是一个生成器# 递归 阅读全文
posted @ 2017-11-29 22:05 窃语 阅读(479) 评论(0) 推荐(1) 编辑
摘要: 1.处理方式 法一 通过HtmlXPathSelectorimport scrapyfrom scrapy.selector import HtmlXPathSelectorclass DmozSpider(scrapy.Spider): name = "use_scrapy" #要调用的名字 al 阅读全文
posted @ 2017-11-28 21:16 窃语 阅读(1363) 评论(0) 推荐(0) 编辑
摘要: #导包 from django.db import transaction try: #django默认是自动提交到数据库,此处设置不让其自动提交 transaction.set_autocommit(False) #处理的部分 transaction.commit() except Excepti 阅读全文
posted @ 2017-11-27 21:31 窃语 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 1.安装pip install Scrapy#一定要以管理员身份运行dos窗口conda install scrapy2.创建项目scrapy startproject hello3.在hello/spiders下创建dmoz_spider.pyimport scrapy class DmozSpi 阅读全文
posted @ 2017-11-24 21:16 窃语 阅读(93) 评论(0) 推荐(0) 编辑
摘要: '''''示例1: 使用语法糖@来装饰函数,相当于“myfunc = fun1(myfunc)”但发现新函数只在第一次被调用,且原函数多调用了一次'''def fun1(func): print("before") func() #第一次调用 print("after") # def func(): 阅读全文
posted @ 2017-11-17 22:26 窃语 阅读(270) 评论(0) 推荐(0) 编辑
摘要: from urllib.request import Request, ProxyHandler from urllib.request import build_opener from bs4 import BeautifulSoup import MySQLdb; import redis from urllib.request import urlopen from lxml import... 阅读全文
posted @ 2017-11-16 19:56 窃语 阅读(153) 评论(0) 推荐(0) 编辑