Try to search your question here, if you can't find : Ask Any Question Now ?

Scrapy can't return reference because it takes up 2 lines

HomeCategory: stackoverflowScrapy can't return reference because it takes up 2 lines
Avatargaurav asked 5 months ago

The first line of the table is easy to scrape because the title “P/E Ratio (TTM)” is written neatly on one line. The other lines of the table however, I can’t seem to scrape because “P/E High – Last 5 Yrs.” takes up 2 lines and I have no idea how to reference it. Same goes for “P/E Low – Last 5 Yrs.”

<tr class="stripe">
        <td>P/E Ratio (TTM)</td>
        <td class="data">11.39</td>
        <td class="data">87.22</td>
        <td class="data">19.22</td>
           P/E High - Last 5 Yrs.</td>
        <td class="data">34.48</td>
        <td class="data">114.12</td>
        <td class="data">24.22</td>
<tr class="stripe">
          P/E Low - Last 5 Yrs.</td>
        <td class="data">10.54</td>
        <td class="data">12.02</td>
        <td class="data">11.39</td>

I am trying to return the numbers in this table. What I have so far that works is:

response.xpath("//td[./preceding-sibling::td[1]='P/E Ratio (TTM)']//text()").extract()
response.xpath("//td[./preceding-sibling::td[2]='P/E Ratio (TTM)']//text()").extract()
response.xpath("//td[./preceding-sibling::td[3]='P/E Ratio (TTM)']//text()").extract()

I have a feeling I’m missing something very obvious here. Here is the link to the site:

Any help would be greatly appreciated. Thank you!

1 Answers
Best Answer
AvatarMikhail answered 5 months ago
Your Answer

9 + 12 =

Popular Tags

WP Facebook Auto Publish Powered By :