Regex 如何用Scrapy解析表中的特定元素
我试图解析表中的某些内容,如下所示:Regex 如何用Scrapy解析表中的特定元素,regex,python-3.x,web-scraping,scrapy,scrapy-spider,Regex,Python 3.x,Web Scraping,Scrapy,Scrapy Spider,我试图解析表中的某些内容,如下所示: <table class="dataTbl col-4"> <tr> <th scope="row">Rent</th> <td>5.5</td> <th scope=
<table class="dataTbl col-4">
<tr>
<th scope="row">Rent</th>
<td>5.5</td>
<th scope="row">Management</th>
<td>3.3</td>
</tr>
<tr>
<th scope="row">Deposit</th>
<td>No</td>
<th scope="row">Other</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Other2</th>
<td>No</td>
<th scope="row">Insurance</th>
<td>Yes</td>
</tr>
</table>
租
5.5
管理层
3.3
押金
不
其他
不
其他2
不
保险
对
我的目标是找到特定的行(例如Rent),如果有匹配项,则提取下一个
标记(例如5.5)中的内容
但是我如何用Python实现它呢
我正在使用Python3/Scrapy 1.3.0
感谢[9]:选择器(text=html).xpath('//th[text()=“Rent”]/以下同级::td[1]')。extract()
输出[9]:['5.5']
text()=“Rent”
标识th
标记以下同级::
获取其同级并使用[1]
获取第一个同级使用python的正则表达式
r'\>text\<.+\n +\<td\>(\d+\.\d+)'
r'\>text\n你今天是我的英雄:)谢谢!顺便说一句,如果你知道上述技术的好来源,请告诉我。
r'\>text\<.+\n +\<td\>(\d+\.\d+)'