Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
E
esi-table-data
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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
esi-data-scrapping
esi-table-data
Commits
d8450ff8
Commit
d8450ff8
authored
Jul 27, 2017
by
Vasyl Bodnaruk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function for following pagination
parent
b6418a72
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletion
+10
-1
cb.py
exa/exa/spiders/cb.py
+10
-1
No files found.
exa/exa/spiders/cb.py
View file @
d8450ff8
...
...
@@ -22,15 +22,19 @@ class CbSpider(BaseSpider):
def
parse
(
self
,
response
):
rows
=
response
.
xpath
(
"//table/tr"
)[
1
:]
company
=
response
.
meta
[
'company'
]
for
i
in
rows
:
item
=
ExaItem
()
item
[
'date'
]
=
i
.
xpath
(
"./td[contains(@class, 'date')]/text()"
)
.
extract_first
()
item
[
'title'
]
=
i
.
xpath
(
"./td/a/text()"
)
.
extract_first
()
item
[
'url'
]
=
i
.
xpath
(
"./td/a/@href"
)
.
extract_first
()
item
.
update
(
self
.
get_common_items
(
company
))
item
[
'media_id'
]
=
self
.
_get_media
(
i
)
print
(
item
)
if
len
(
rows
)
!=
0
:
yield
scrapy
.
Request
(
self
.
_next_url
(
response
.
url
),
callback
=
self
.
parse
,
meta
=
response
.
meta
)
def
_get_media
(
self
,
elem
):
media_name
=
elem
.
xpath
(
"./td[contains(@class, 'article')]/span/text()"
)
.
extract_first
()
media_url
=
elem
.
xpath
(
"./td/a/@data_publisher"
)
.
extract_first
()
...
...
@@ -41,3 +45,8 @@ class CbSpider(BaseSpider):
else
:
media
=
media
[
0
][
0
]
return
media
def
_next_url
(
self
,
url
):
pos
=
url
.
rfind
(
'='
)
+
1
next_page
=
int
(
url
[
pos
:])
+
1
return
url
[:
pos
]
+
str
(
next_page
)
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