Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何用Scrapy解析表中的特定元素_Regex_Python 3.x_Web Scraping_Scrapy_Scrapy Spider - Fatal编程技术网

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+)'