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
5079a7b9
Commit
5079a7b9
authored
Apr 26, 2017
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajustes.
parent
2cc23082
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
23 deletions
+28
-23
__init__.pyc
lajornada/lajornada/__init__.pyc
+0
-0
settings.pyc
lajornada/lajornada/settings.pyc
+0
-0
__init__.pyc
lajornada/lajornada/spiders/__init__.pyc
+0
-0
noticias.py
lajornada/lajornada/spiders/noticias.py
+28
-23
noticias.pyc
lajornada/lajornada/spiders/noticias.pyc
+0
-0
No files found.
lajornada/lajornada/__init__.pyc
View file @
5079a7b9
No preview for this file type
lajornada/lajornada/settings.pyc
View file @
5079a7b9
No preview for this file type
lajornada/lajornada/spiders/__init__.pyc
View file @
5079a7b9
No preview for this file type
lajornada/lajornada/spiders/noticias.py
View file @
5079a7b9
...
...
@@ -7,56 +7,63 @@ uso:
import
scrapy
import
re
TAG_RE
=
re
.
compile
(
r'<[^>]+>'
)
def
remove_tags
(
text
):
return
TAG_RE
.
sub
(
''
,
text
)
class
NoticiasItem
(
scrapy
.
Item
):
title
=
scrapy
.
Field
()
text
=
scrapy
.
Field
()
date
=
scrapy
.
Field
()
location
=
scrapy
.
Field
()
date
=
scrapy
.
Field
()
location
=
scrapy
.
Field
()
author
=
scrapy
.
Field
()
topic
=
scrapy
.
Field
()
url
=
scrapy
.
Field
()
topic
=
scrapy
.
Field
()
url
=
scrapy
.
Field
()
class
NoticiasSpider
(
scrapy
.
Spider
):
name
=
"noticias"
def
start_requests
(
self
):
"""Lista de url a explorar."""
year
=
getattr
(
self
,
'year'
,
None
)
month
=
getattr
(
self
,
'month'
,
None
)
day
=
getattr
(
self
,
'day'
,
None
)
self
.
baseURL
=
'http://www.jornada.unam.mx/'
+
year
+
'/'
+
month
+
'/'
+
day
+
'/'
urls
=
[
self
.
baseURL
+
"opinion"
,
self
.
baseURL
+
"politica"
,
self
.
baseURL
+
"economia"
,
self
.
baseURL
+
"mundo"
,
self
.
baseURL
+
"estados"
,
self
.
baseURL
+
"capital"
,
self
.
baseURL
+
"sociedad"
,
self
.
baseURL
+
"ciencias"
,
self
.
baseURL
+
"cultura"
,
self
.
baseURL
+
"espectaculos"
,
self
.
baseURL
+
"deporte"
,
#
self.baseURL+"politica",
#
self.baseURL+"economia",
#
self.baseURL+"mundo",
#
self.baseURL+"estados",
#
self.baseURL+"capital",
#
self.baseURL+"sociedad",
#
self.baseURL+"ciencias",
#
self.baseURL+"cultura",
#
self.baseURL+"espectaculos",
#
self.baseURL+"deporte",
]
for
url
in
urls
:
yield
scrapy
.
Request
(
url
=
url
,
callback
=
self
.
parse
)
def
parse
(
self
,
response
):
"""parser principal."""
"""parser principal."""
item
=
NoticiasItem
()
for
noticia
in
response
.
css
(
'a.cabeza'
):
url
=
self
.
baseURL
+
noticia
.
css
(
'::attr(href)'
)
.
extract_first
()
url
=
self
.
baseURL
+
noticia
.
css
(
'::attr(href)'
)
.
extract_first
()
yield
scrapy
.
Request
(
url
,
callback
=
self
.
parse_dir_contents
)
def
parse_dir_contents
(
self
,
response
):
"""Parser para la pagina de cada noticia."""
"""Parser para la pagina de cada noticia."""
item
=
NoticiasItem
()
item
[
'title'
]
=
response
.
css
(
'div.cabeza::text'
)
.
extract_first
()
item
[
'url'
]
=
response
.
url
...
...
@@ -64,6 +71,4 @@ class NoticiasSpider(scrapy.Spider):
item
[
'location'
]
=
response
.
css
(
'p.s-s::text'
)
.
extract_first
()
item
[
'text'
]
=
remove_tags
(
response
.
css
(
'div.text'
)
.
extract_first
()
)
item
[
'topic'
]
=
response
.
css
(
'img.title::attr(title)'
)
.
extract_first
()
yield
item
yield
item
\ No newline at end of file
lajornada/lajornada/spiders/noticias.pyc
View file @
5079a7b9
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