Reorganize example code
This commit is contained in:
parent
7c10d1c4b0
commit
6580c266dd
8 changed files with 143 additions and 56 deletions
21
code/exercise-solutions/exercise-1.py
Normal file
21
code/exercise-solutions/exercise-1.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
import scrapy
|
||||
|
||||
|
||||
class QuotesSpider(scrapy.Spider):
|
||||
name = "quotes"
|
||||
allowed_domains = ["quotes.toscrape.com"]
|
||||
start_urls = ["https://quotes.toscrape.com"]
|
||||
|
||||
def parse(self, response):
|
||||
quotes = response.css(".quote")
|
||||
for quote in quotes:
|
||||
yield {
|
||||
"quote": quote.css(".text::text").get(),
|
||||
"author": quote.css(".author::text").get(),
|
||||
"author_url": response.urljoin(quote.css("span a::attr(href)").get()),
|
||||
"tags": quote.css(".tag *::text").getall(),
|
||||
}
|
||||
|
||||
yield scrapy.Request(
|
||||
response.urljoin(response.css(".next a::attr(href)").get())
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue