scrapy

scrapyd api

家住魔仙堡 提交于 2020-02-22 07:28:36
为了方便使用scrapy JSON api 而将其进行包装 关于egg包的上传,则需要在本文件所处目录创建一个eggs文件夹,将egg格式文件放入即可 import requests import demjson import datetime import pandas as pd import os import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) DEFAULT_SCRAPYDIP = '127.0.0.1' DEFAULT_SCRAPYDPORT = '6800' class ScrapydApi(object): def __init__(self, ip=DEFAULT_SCRAPYDIP, port=DEFAULT_SCRAPYDPORT): self.ip = ip self.port = port self.url = 'http://' + ip + ':' + port def addversion(self, project_name, version, egg): npth = os.path

虚拟环境搭建与scrapy爬虫项目创建

戏子无情 提交于 2020-02-21 18:21:30
虚拟环境搭建(virtualenv): pip 安装 virtualenvwrapper-win 统一管理虚拟环境,放在环境变量WORKON_HOME路径下(Evns文件夹下)然后可以在cmd中执行下列命令: workon 显示当前所有虚拟环境; workon + 名称 进入相应虚拟环境; mkvirtualenv + 名称 创建虚拟环境。 安装库: (镜像快速下载)镜像: pip install -i https://pypi.douban.com/simple 库名 (找不到时可用)进入 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载对应版本 whl 文件,cmd 进入所在目录,用 workon 进入虚拟环境,再pip install whl文件名 弯路经验: 有时候 pip 安装 scrapy 库会报错,可以试试先安装twisted,然后安装 scrapy 创建项目: scrapy startproject + 项目名 创建爬虫: 进入项目目录; scrapy genspider + 爬虫名 + 网址 在 pycharm 打开后,spider 文件夹右键 synchronize(同步) 就能显示爬虫文件 运行爬虫: scrapy crawl + 爬虫名 pycharm 中通过在项目文件夹中新建 main文件,execute([

第8月第22天 python scrapy

僤鯓⒐⒋嵵緔 提交于 2020-02-21 13:36:33
1. 503 cd /Users/temp/Downloads/LagouSpider-master 504 ls 505 ls 506 ls lagou/settings.py 507 cat lagou/settings.py 508 ls 509 python main.py 510 cat main.py 511 sudo pip install scrapy 512 python main.py 513 sudo pip uninstall six 514 sudo easy_install six 515 python main.py 516 sudo pip install --upgrade six scrapy 517 sudo pip install --upgrade six scrapy 518 sudo pip install --upgrade pip 519 sudo pip install --upgrade six scrapy 520 ls 521 python man 522 python main.py 523 sudo pip install twisted==13.1.0 524 python main.py https://github.com/hk029/LagouSpider 2. 'module' object has no

Selenium is not loading TikTok pages

末鹿安然 提交于 2020-02-21 05:01:40
问题 I'm implementing a TikTok crawler using selenium and scrapy start_urls = ['https://www.tiktok.com/trending'] .... def parse(self, response): options = webdriver.ChromeOptions() from fake_useragent import UserAgent ua = UserAgent() user_agent = ua.random options.add_argument(f'user-agent={user_agent}') options.add_argument('window-size=800x841') driver = webdriver.Chrome(chrome_options=options) driver.get(response.url) The crawler open Chrome but it does not load videos. Image loading The same

Selenium is not loading TikTok pages

随声附和 提交于 2020-02-21 05:01:13
问题 I'm implementing a TikTok crawler using selenium and scrapy start_urls = ['https://www.tiktok.com/trending'] .... def parse(self, response): options = webdriver.ChromeOptions() from fake_useragent import UserAgent ua = UserAgent() user_agent = ua.random options.add_argument(f'user-agent={user_agent}') options.add_argument('window-size=800x841') driver = webdriver.Chrome(chrome_options=options) driver.get(response.url) The crawler open Chrome but it does not load videos. Image loading The same

Selenium is not loading TikTok pages

我只是一个虾纸丫 提交于 2020-02-21 05:00:10
问题 I'm implementing a TikTok crawler using selenium and scrapy start_urls = ['https://www.tiktok.com/trending'] .... def parse(self, response): options = webdriver.ChromeOptions() from fake_useragent import UserAgent ua = UserAgent() user_agent = ua.random options.add_argument(f'user-agent={user_agent}') options.add_argument('window-size=800x841') driver = webdriver.Chrome(chrome_options=options) driver.get(response.url) The crawler open Chrome but it does not load videos. Image loading The same

2020-02-20(scrapy框架相关)

南楼画角 提交于 2020-02-20 15:53:40
1.请求传参(item): 应用场景:解析的数据不在同一张页面中 Request(callback,meta={}) 2.LOG_LEVEL LOG_FILE 3.下载中间件: 批量拦截请求(代理ip和UA)和响应(处理页面数据) 4.如何在scrapy使用selenium 1.在spider的init方法中实例化一个浏览器对象 2.在spider的closed方法中关闭浏览器对象 3.在下载中间件类的process_response方法中接收spider中的浏览器对象 4.处理执行相关自动化操作(发起请求,获取页面数据) 5.实例化一个新的响应对象(from scrapy.http import HtmlResponse),且将页面数据存储到该对象中 6.返回新的响应对象 7.在配置文件中开启中间件 5.如何提升scrapy爬取数据的效率: 增加并发: 默认scrapy开启的并发线程为32个,可以适当进行增加。 在settings配置文件中修改CONCURRENT_REQUESTS = 100值为100,并发设置成了为100 降低日志级别: 在运行scrapy时,会有大量日志信息的输出,为了减少CPU的使用率。 可以设置log输出信息为INFO或者ERROR即可。 在配置文件中编写:LOG_LEVEL = ‘INFO’ 禁止cookie: 如果不是真的需要cookie

Python爬虫框架Scrapy入门(二)第一个爬虫程序:使用xpath爬取起点中文网

≡放荡痞女 提交于 2020-02-20 15:08:31
一、需求分析 爬取起点中文网24小时热销榜的小说: https://www.qidian.com/rank/hotsales?style=1 作为第一个爬虫程序,我们只爬取第一页每本小说的名称、作者、类型、以及是否连载。 二、创建项目 打开命令行,切换到要保存工程的文件路径后,输入 scrapy startproject qidian_hot 创建一个名为qidian_hot的项目工程。 打开该文件路径,可以看到生成了一个qidian_hot的文件夹,里面便保存着scrapy的相关文件。 三、分析页面 用谷歌浏览器或其他带有开发者工具的浏览器,打开起点中文网24小时热销榜的网址 https://www.qidian.com/rank/hotsales?style=1 然后打开开发者工具 点击刷新页面后,找到网页响应的html代码 点击右上角的箭头,然后把鼠标移到小说的信息栏,单击,会看到右边的代码框会自动定位到该信息对应的代码。 我么可以看到在这个下面对应四个标签,分别对应这本小说的信息 展开标签,可以看到里面的内容,接下来我们只需要创建爬虫得到响应,并从中提取我们想要的信息即可 四、实现爬虫 打开我们之前建立的爬虫工程,在spider目录下建立爬虫文件 qidian_spider.py 导入需要用到的库 from scrapy import Request from scrapy

Error while installing Scrapy error: Microsoft Visual C++ 14.0 is required

*爱你&永不变心* 提交于 2020-02-19 05:58:12
问题 I found about scrapy that is a great tool scraping so i tried to install scrapy on my machine, but when i tried to do pip install scrapy it installed for a while and threw me this error.. error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools I tried to install it in virtual environment but still the problem persists. EDIT: here is what i got after the error.. error: Microsoft Visual C++ 14.0 is

超简单Windows安装Scrapy (仅需一步)

醉酒当歌 提交于 2020-02-18 20:08:16
网上很多关于windows安装Scrapy的教程都非常的繁琐,请看我给大家分享的教程,非常简单 一步完成。 超简单的安装方法: 下载地址: https://www.continuum.io/downloads   Windows用户只修要点击那个Download for 旁边的Win标徽的图标即可进入Windows版本下载页 给出懒人链接: https://www.continuum.io/downloads#windows 根据不同的系统版本下载对应的程序版本 放出 Anaconda3-4.3.1-Windows 64位 版本的下载链接(可直接使用迅雷下载): https://repo.continuum.io/archive/Anaconda3-4.3.1-Windows-x86_64.exe    然后你想安装你所要安装的库 conda install scrapy   安装完成。 再来看看传统的安装方法(不建议新手使用): 首先时依赖包: 目前由于py3.5还不能完美支持scrapy,这里以py2.7为准 1、windows下安装lxml(下载之后不要改名字,要安装先进入到lxml文件所在的目录) 下载地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/ 使用 pip install lxml-3.4.4-cp27-none-win32