Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
ScrapyTutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Gusev
ScrapyTutorial
Commits
6c10a062
Commit
6c10a062
authored
5 years ago
by
Anton Gusev
Browse files
Options
Downloads
Patches
Plain Diff
add logging.debug for BooksSpider
parent
6b39c55f
No related branches found
Branches containing commit
No related tags found
5 merge requests
!5
Develop
,
!4
Develop
,
!3
Develop
,
!2
Develop
,
!1
Develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/spiders/books_spider.py
+11
-6
11 additions, 6 deletions
src/spiders/books_spider.py
with
11 additions
and
6 deletions
src/spiders/books_spider.py
+
11
−
6
View file @
6c10a062
import
scrapy
from
scrapy
import
Spider
import
re
import
re
from
items.BookItem
import
BookItem
from
items.BookItem
import
BookItem
from
database.connectors.BookConnector
import
BookConnector
from
database.connectors.BookConnector
import
BookConnector
import
logging
class
BooksSpider
(
BookConnector
,
scrapy
.
Spider
):
class
BooksSpider
(
Spider
,
BookConnector
):
name
=
'
books
'
name
=
'
books
'
start_urls
=
[
'
http://books.toscrape.com/
'
]
start_urls
=
[
'
http://books.toscrape.com/
'
]
page
=
1
def
parse
(
self
,
response
):
def
parse
(
self
,
response
):
self
.
logger
.
debug
(
'
Current page: {}
'
.
format
(
self
.
page
))
# follow links to book pages
# follow links to book pages
for
idx
,
href
in
enumerate
(
response
.
css
(
'
div.image_container a::attr(href)
'
)):
# TODO delete enumerate
for
idx
,
href
in
enumerate
(
response
.
css
(
'
div.image_container a::attr(href)
'
)):
# TODO delete enumerate
yield
response
.
follow
(
href
,
self
.
parse_book
)
yield
response
.
follow
(
href
,
self
.
parse_book
,
meta
=
{
'
idx
'
:
idx
}
)
# pagination
# pagination
next_page
=
response
.
css
(
'
li.next a::attr(href)
'
).
get
()
next_page
=
response
.
css
(
'
li.next a::attr(href)
'
).
get
()
if
next_page
is
not
None
:
if
next_page
is
not
None
:
self
.
page
+=
1
yield
response
.
follow
(
next_page
,
callback
=
self
.
parse
)
yield
response
.
follow
(
next_page
,
callback
=
self
.
parse
)
def
parse_book
(
self
,
response
):
def
parse_book
(
self
,
response
):
self
.
logger
.
debug
(
'
Index book in page: {}
'
.
format
(
response
.
meta
.
get
(
'
idx
'
)))
book
=
BookItem
()
book
=
BookItem
()
table_data
=
response
.
css
(
'
table td::text
'
).
getall
()
table_data
=
response
.
css
(
'
table td::text
'
).
getall
()
...
@@ -50,4 +55,4 @@ class BooksSpider(BookConnector, scrapy.Spider):
...
@@ -50,4 +55,4 @@ class BooksSpider(BookConnector, scrapy.Spider):
if
'
Four
'
in
class_all
:
if
'
Four
'
in
class_all
:
return
4
return
4
if
'
Five
'
in
class_all
:
if
'
Five
'
in
class_all
:
return
5
return
5
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment