Reputation:
I am creating a dictionary using yield, assigning a value to it seems to cause some kind of an error. My value for yield is a variable title
which contains title = response.html("h1").extract()
import scrapy
class QuoteSpider(scrapy.Spider):
name = "Quotes"
start_urls = [
"http://quotes.toscrape.com/"
]
def parse(self, response):
title = response.html("h1").extract()
yield (' titletext ' : title)
I've tried replacing yield
with return
but that fails to extract the HTML. When I run the code, I get the error. SyntaxError: invalid syntax
in yield (' titletext ' : title)
What is the correct syntax for yield?
Without the error, I hope to be able to extract the h1 element from this website
Upvotes: 0
Views: 1305
Reputation: 236140
I think you meant this:
yield { 'titletext': title }
The colon :
means that it's a key-value pair, and that needs to go inside a dictionary, which is delimited by {}
not ()
.
Upvotes: 1