Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
crawlersNoticias
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
m3
crawlersNoticias
Commits
c908a556
Commit
c908a556
authored
Oct 12, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
laJornadaMaya update
parent
566f8f06
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
400 additions
and
219 deletions
+400
-219
items.py
descarga_hacia_atras/laJornadaMaya/laJornadaMaya/items.py
+9
-3
middlewares.py
...ga_hacia_atras/laJornadaMaya/laJornadaMaya/middlewares.py
+52
-5
pipelines.py
...arga_hacia_atras/laJornadaMaya/laJornadaMaya/pipelines.py
+66
-2
settings.py
descarga_hacia_atras/laJornadaMaya/laJornadaMaya/settings.py
+17
-17
noticias.py
...cia_atras/laJornadaMaya/laJornadaMaya/spiders/noticias.py
+255
-191
scrapy.cfg
descarga_hacia_atras/laJornadaMaya/scrapy.cfg
+1
-1
No files found.
descarga_hacia_atras/laJornadaMaya/laJornadaMaya/items.py
View file @
c908a556
...
...
@@ -3,12 +3,18 @@
# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html
# http
s
://doc.scrapy.org/en/latest/topics/items.html
import
scrapy
class
Lajornadamaya
Item
(
scrapy
.
Item
):
class
Noticias
Item
(
scrapy
.
Item
):
# define the fields for your item here like:
# name = scrapy.Field()
pass
title
=
scrapy
.
Field
()
text
=
scrapy
.
Field
()
date
=
scrapy
.
Field
()
location
=
scrapy
.
Field
()
author
=
scrapy
.
Field
()
topic
=
scrapy
.
Field
()
url
=
scrapy
.
Field
()
descarga_hacia_atras/laJornadaMaya/laJornadaMaya/middlewares.py
View file @
c908a556
...
...
@@ -3,7 +3,7 @@
# Define here the models for your spider middleware
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/spider-middleware.html
# http
s
://doc.scrapy.org/en/latest/topics/spider-middleware.html
from
scrapy
import
signals
...
...
@@ -20,14 +20,14 @@ class LajornadamayaSpiderMiddleware(object):
crawler
.
signals
.
connect
(
s
.
spider_opened
,
signal
=
signals
.
spider_opened
)
return
s
def
process_spider_input
(
response
,
spider
):
def
process_spider_input
(
self
,
response
,
spider
):
# Called for each response that goes through the spider
# middleware and into the spider.
# Should return None or raise an exception.
return
None
def
process_spider_output
(
response
,
result
,
spider
):
def
process_spider_output
(
self
,
response
,
result
,
spider
):
# Called with the results returned from the Spider, after
# it has processed the response.
...
...
@@ -35,7 +35,7 @@ class LajornadamayaSpiderMiddleware(object):
for
i
in
result
:
yield
i
def
process_spider_exception
(
response
,
exception
,
spider
):
def
process_spider_exception
(
self
,
response
,
exception
,
spider
):
# Called when a spider or process_spider_input() method
# (from other spider middleware) raises an exception.
...
...
@@ -43,7 +43,7 @@ class LajornadamayaSpiderMiddleware(object):
# or Item objects.
pass
def
process_start_requests
(
start_requests
,
spider
):
def
process_start_requests
(
s
elf
,
s
tart_requests
,
spider
):
# Called with the start requests of the spider, and works
# similarly to the process_spider_output() method, except
# that it doesn’t have a response associated.
...
...
@@ -54,3 +54,50 @@ class LajornadamayaSpiderMiddleware(object):
def
spider_opened
(
self
,
spider
):
spider
.
logger
.
info
(
'Spider opened:
%
s'
%
spider
.
name
)
class
LajornadamayaDownloaderMiddleware
(
object
):
# Not all methods need to be defined. If a method is not defined,
# scrapy acts as if the downloader middleware does not modify the
# passed objects.
@
classmethod
def
from_crawler
(
cls
,
crawler
):
# This method is used by Scrapy to create your spiders.
s
=
cls
()
crawler
.
signals
.
connect
(
s
.
spider_opened
,
signal
=
signals
.
spider_opened
)
return
s
def
process_request
(
self
,
request
,
spider
):
# Called for each request that goes through the downloader
# middleware.
# Must either:
# - return None: continue processing this request
# - or return a Response object
# - or return a Request object
# - or raise IgnoreRequest: process_exception() methods of
# installed downloader middleware will be called
return
None
def
process_response
(
self
,
request
,
response
,
spider
):
# Called with the response returned from the downloader.
# Must either;
# - return a Response object
# - return a Request object
# - or raise IgnoreRequest
return
response
def
process_exception
(
self
,
request
,
exception
,
spider
):
# Called when a download handler or a process_request()
# (from other downloader middleware) raises an exception.
# Must either:
# - return None: continue processing this exception
# - return a Response object: stops process_exception() chain
# - return a Request object: stops process_exception() chain
pass
def
spider_opened
(
self
,
spider
):
spider
.
logger
.
info
(
'Spider opened:
%
s'
%
spider
.
name
)
descarga_hacia_atras/laJornadaMaya/laJornadaMaya/pipelines.py
View file @
c908a556
...
...
@@ -3,9 +3,73 @@
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
# See: http
s
://doc.scrapy.org/en/latest/topics/item-pipeline.html
import
json
from
collections
import
OrderedDict
class
JsonWriterPipeline
(
object
):
def
__init__
(
self
,
filename
):
self
.
filename
=
filename
@
classmethod
def
from_crawler
(
cls
,
crawler
):
# Here you get whatever value was passed through the "filename" command line parameter
settings
=
crawler
.
settings
filename
=
settings
.
get
(
'filename'
)
# Instantiate the pipeline with the file name
return
cls
(
filename
)
def
open_spider
(
self
,
spider
):
self
.
counter
=
0
self
.
file
=
open
(
self
.
filename
,
'w'
)
self
.
file
.
write
(
"["
)
def
close_spider
(
self
,
spider
):
self
.
file
.
write
(
"]"
)
self
.
file
.
close
()
class
LajornadamayaPipeline
(
object
):
def
process_item
(
self
,
item
,
spider
):
# print("this is my item", item)
row
=
[]
try
:
row
.
append
((
"date"
,
item
[
'date'
]))
except
:
pass
try
:
row
.
append
((
"topic"
,
item
[
'topic'
]))
except
:
pass
try
:
row
.
append
((
"title"
,
item
[
'title'
]))
except
:
pass
try
:
row
.
append
((
"author"
,
item
[
'author'
]))
except
:
pass
try
:
row
.
append
((
"location"
,
item
[
'location'
]))
except
:
pass
try
:
row
.
append
((
"text"
,
item
[
'text'
]))
except
:
pass
try
:
row
.
append
((
"url"
,
item
[
'url'
]))
except
:
pass
line
=
OrderedDict
(
row
)
self
.
counter
+=
1
if
self
.
counter
==
1
:
self
.
file
.
write
(
json
.
dumps
(
line
))
elif
self
.
counter
>
1
:
self
.
file
.
write
(
",
\n
"
+
json
.
dumps
(
line
))
return
item
descarga_hacia_atras/laJornadaMaya/laJornadaMaya/settings.py
View file @
c908a556
...
...
@@ -5,9 +5,9 @@
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
# http://doc.scrapy.org/en/latest/topics/settings.html
# http
://scrapy.readthedocs
.org/en/latest/topics/downloader-middleware.html
# http
://scrapy.readthedocs
.org/en/latest/topics/spider-middleware.html
# http
s
://doc.scrapy.org/en/latest/topics/settings.html
# http
s://doc.scrapy
.org/en/latest/topics/downloader-middleware.html
# http
s://doc.scrapy
.org/en/latest/topics/spider-middleware.html
BOT_NAME
=
'laJornadaMaya'
...
...
@@ -19,21 +19,21 @@ NEWSPIDER_MODULE = 'laJornadaMaya.spiders'
#USER_AGENT = 'laJornadaMaya (+http://www.yourdomain.com)'
# Obey robots.txt rules
ROBOTSTXT_OBEY
=
True
#
ROBOTSTXT_OBEY = True
# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32
# Configure a delay for requests for the same website (default: 0)
# See http
://scrapy.readthedocs
.org/en/latest/topics/settings.html#download-delay
# See http
s://doc.scrapy
.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY = 3
DOWNLOAD_DELAY
=
0.5
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16
# Disable cookies (enabled by default)
#
COOKIES_ENABLED = False
COOKIES_ENABLED
=
False
# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False
...
...
@@ -45,31 +45,31 @@ ROBOTSTXT_OBEY = True
#}
# Enable or disable spider middlewares
# See http
://scrapy.readthedocs
.org/en/latest/topics/spider-middleware.html
# See http
s://doc.scrapy
.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
# 'laJornadaMaya.middlewares.LajornadamayaSpiderMiddleware': 543,
#}
# Enable or disable downloader middlewares
# See http
://scrapy.readthedocs
.org/en/latest/topics/downloader-middleware.html
# See http
s://doc.scrapy
.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
# 'laJornadaMaya.middlewares.
MyCustom
DownloaderMiddleware': 543,
# 'laJornadaMaya.middlewares.
Lajornadamaya
DownloaderMiddleware': 543,
#}
# Enable or disable extensions
# See http
://scrapy.readthedocs
.org/en/latest/topics/extensions.html
# See http
s://doc.scrapy
.org/en/latest/topics/extensions.html
#EXTENSIONS = {
# 'scrapy.extensions.telnet.TelnetConsole': None,
#}
# Configure item pipelines
# See http
://scrapy.readthedocs
.org/en/latest/topics/item-pipeline.html
#
ITEM_PIPELINES = {
# 'laJornadaMaya.pipelines.Lajornadamaya
Pipeline': 300,
#
}
# See http
s://doc.scrapy
.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES
=
{
'laJornadaMaya.pipelines.JsonWriter
Pipeline'
:
300
,
}
# Enable and configure the AutoThrottle extension (disabled by default)
# See http://doc.scrapy.org/en/latest/topics/autothrottle.html
# See http
s
://doc.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
...
...
@@ -82,7 +82,7 @@ ROBOTSTXT_OBEY = True
#AUTOTHROTTLE_DEBUG = False
# Enable and configure HTTP caching (disabled by default)
# See http
://scrapy.readthedocs
.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
# See http
s://doc.scrapy
.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
...
...
descarga_hacia_atras/laJornadaMaya/laJornadaMaya/spiders/noticias.py
View file @
c908a556
This diff is collapsed.
Click to expand it.
descarga_hacia_atras/laJornadaMaya/scrapy.cfg
View file @
c908a556
# Automatically created by: scrapy startproject
#
# For more information about the [deploy] section see:
# https://scrapyd.readthedocs.
org
/en/latest/deploy.html
# https://scrapyd.readthedocs.
io
/en/latest/deploy.html
[settings]
default = laJornadaMaya.settings
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment