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
2d809dad
Commit
2d809dad
authored
Aug 29, 2017
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crawlers
parent
11c4aa01
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
+15
-10
noticias.py
...rga_por_dia/laJornadaZac/laJornadaZac/spiders/noticias.py
+15
-10
noticias.pyc
...ga_por_dia/laJornadaZac/laJornadaZac/spiders/noticias.pyc
+0
-0
No files found.
descarga_por_dia/laJornadaZac/laJornadaZac/spiders/noticias.py
View file @
2d809dad
...
@@ -8,6 +8,7 @@ TAG_RE = re.compile(r'<[^>]+>')
...
@@ -8,6 +8,7 @@ TAG_RE = re.compile(r'<[^>]+>')
def
remove_tags
(
text
):
def
remove_tags
(
text
):
return
TAG_RE
.
sub
(
''
,
text
)
return
TAG_RE
.
sub
(
''
,
text
)
class
NoticiasItem
(
scrapy
.
Item
):
class
NoticiasItem
(
scrapy
.
Item
):
title
=
scrapy
.
Field
()
title
=
scrapy
.
Field
()
text
=
scrapy
.
Field
()
text
=
scrapy
.
Field
()
...
@@ -17,6 +18,7 @@ class NoticiasItem(scrapy.Item):
...
@@ -17,6 +18,7 @@ class NoticiasItem(scrapy.Item):
topic
=
scrapy
.
Field
()
topic
=
scrapy
.
Field
()
url
=
scrapy
.
Field
()
url
=
scrapy
.
Field
()
class
QuotesSpider
(
scrapy
.
Spider
):
class
QuotesSpider
(
scrapy
.
Spider
):
name
=
"noticias"
name
=
"noticias"
def
start_requests
(
self
):
def
start_requests
(
self
):
...
@@ -30,6 +32,7 @@ class QuotesSpider(scrapy.Spider):
...
@@ -30,6 +32,7 @@ class QuotesSpider(scrapy.Spider):
for
url
in
urls
:
for
url
in
urls
:
yield
scrapy
.
Request
(
url
=
url
,
callback
=
self
.
parse
)
yield
scrapy
.
Request
(
url
=
url
,
callback
=
self
.
parse
)
def
parse
(
self
,
response
):
def
parse
(
self
,
response
):
pagination
=
response
.
xpath
(
'//div[@class="pagination"]/a/@href'
)
.
extract
()
pagination
=
response
.
xpath
(
'//div[@class="pagination"]/a/@href'
)
.
extract
()
if
(
len
(
pagination
)
>
0
):
if
(
len
(
pagination
)
>
0
):
...
@@ -43,14 +46,16 @@ class QuotesSpider(scrapy.Spider):
...
@@ -43,14 +46,16 @@ class QuotesSpider(scrapy.Spider):
else
:
else
:
yield
scrapy
.
Request
(
url
=
response
.
url
,
callback
=
self
.
parse_page
,
dont_filter
=
True
)
yield
scrapy
.
Request
(
url
=
response
.
url
,
callback
=
self
.
parse_page
,
dont_filter
=
True
)
def
parse_page
(
self
,
response
):
def
parse_page
(
self
,
response
):
for
link
in
response
.
xpath
(
'//h2[@class="cat-list-title"]/a/@href'
)
.
extract
():
for
link
in
response
.
xpath
(
'//h2[@class="cat-list-title"]/a/@href'
)
.
extract
():
yield
scrapy
.
Request
(
url
=
link
,
callback
=
self
.
parse_item
)
yield
scrapy
.
Request
(
url
=
link
,
callback
=
self
.
parse_item
)
def
parse_item
(
self
,
response
):
def
parse_item
(
self
,
response
):
item
=
NoticiasItem
()
item
=
NoticiasItem
()
text
=
''
text
=
''
item
[
'date'
]
=
response
.
xpath
(
'//
time[@class="entry-date updated"]/@datetime
'
)
.
extract_first
()
item
[
'date'
]
=
response
.
xpath
(
'//
*[@class="entry-post-meta"]'
)
.
css
(
'time::attr(content)
'
)
.
extract_first
()
item
[
'title'
]
=
response
.
xpath
(
'//h1[@class="entry-title"]/text()'
)
.
extract_first
()
item
[
'title'
]
=
response
.
xpath
(
'//h1[@class="entry-title"]/text()'
)
.
extract_first
()
item
[
'topic'
]
=
response
.
xpath
(
'//*[@class="entry-cat"]/a/text()'
)
.
extract_first
()
item
[
'topic'
]
=
response
.
xpath
(
'//*[@class="entry-cat"]/a/text()'
)
.
extract_first
()
...
...
descarga_por_dia/laJornadaZac/laJornadaZac/spiders/noticias.pyc
View file @
2d809dad
No preview for this file type
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