Reputation: 91
I'm using this code. The last two Values are there like that because I was testing to see if either one of them will work- they don't, though.
def parse_again(self, response):
sel = Selector(response)
meta = sel.xpath('//div[@class="LWimg"]')
items = []
for m in meta:
item = PageItem()
item['link'] = response.url
item['Stake'] = m.select('//div[@class="stakedLW"]/h1/text()').extract()
item['Value'] = m.select('//p[@class="value"]/text()').extract()
item['Value'] = m.select('//div[@class="value"]/span/span/text()').extract()
items.append(item)
return items
to retrieve data from this html source code
<div class="LWimg">
<div class="stakedLW">
<span class="title">Stake</span>
<span class="value">5.00</span>
<span class="currency">€</span>
My items.py
looks like this
from scrapy.item import Item, Field
class Page(Item):
Stake = Field()
Value = Field()
The problem is that data is not retrieved, i.e. nothing is saved into a .csv
in the end.
Any input is welcome.
Upvotes: 1
Views: 226
Reputation: 18799
You are populating the Value
field twice, so just the last one will work, and I think the correct way should be:
item['Value'] = response.xpath('//div[@class="stakedLW"]//span[@class="value"]/text()').extract_first()
The other fields are not necessary, just the link
one.
Upvotes: 2