xpath - How to turn a table into a single block of text with scrapy -


i trying scrape table looks below.

<table class="table">     <caption>caption</caption>     <tbody>         <tr>             <th scope="row">title</th>             <td>detail</td>         </tr>         <tr>             <th scope="row">title 2</th>             <td>detail 2</td>         </tr>     </tbody> </table> 

how set scrapy output file generates output similar below?!

title: detail title2: detail2 

currently can text using 2 css selectors (one td's , 1 th's) love able combine these!

unfortunately number of rows differs page page..

using xpath:

tabledata={} in response.xpath("//table[@class='table']//tr")     tabledata[i.xpath("th/text()").extract_first()] = i.xpath("td/text()").extract_first() 

output

{"title":"detail", "title 2":"detail 2"} 

Comments