Yes, it works.
Thanks,
Massimo
On 29/02/16 12:41, Paul Tremberth wrote:
Hello Massimo,
inside loops over selector xpath() results,
you should always use *relative* XPath expressions (starting with ./,
i.e. with "." (dot))
instead of absolute ones (starting with /)
so that the XPath relates to that specific element you are on in the
loop iteration.
Absolute XPath expressions run from the root of the tree
So you would have something like
|
forsel inresponse.xpath('//*[starts-with(@class, "row")]'):
print"SEL: ",sel
starter =sel.xpath('.//*[starts-with(@title, "No message to read")]')
print"STARTER: ",starter
|
Let us know if this helps.
Paul.
On Monday, February 29, 2016 at 12:34:26 PM UTC+1, Massimo Canonico
wrote:
Hi all,
I'm trying to extract data from a bulletin board website from
specific
board. Each board has different threads and each thread has some
posts.
Now I'm looking for the title of each thread.
In the parse function, if I use
response.xpath('//*[starts-with(@class, "row")]')
I can obtain 28 different object like this "<Selector
xpath='//*[starts-with(@class, "row")]' data=u'<li class="row bg1
announce">\n\t\t\t<dl cla'>" and it is ok, since I have 28 threads.
but if I'm trying to use xpath in one specific selector, in order to
extract info, I get info to all 28 elements.
My code looks like this one:
for sel in response.xpath('//*[starts-with(@class, "row")]'):
print "SEL: ", sel
starter = sel.xpath('//*[starts-with(@title, "No message to
read")]')
print "STARTER: ", starter
the first print of starter showed 28 element and not just one.
The previous for cycle prints correctly each of the 28 element for
SEL
but for STARTER I obtain always the same output.
In other words, for each element of the 28 returned by
response.xpath('//*[starts-with(@class, "row")]')
I would like to execute another xpath in order to extract other info.
Am sure that I'm missing something on how xpath works.
Sorry about that, I'm quite new on scrapy and xpath.
Thanks in advance,
Massimo
--
You received this message because you are subscribed to the Google Groups
"scrapy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/scrapy-users.
For more options, visit https://groups.google.com/d/optout.