Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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/3/xpath/2.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
python xpath相对路径get<;p>;之前<;br>;_Python_Xpath - Fatal编程技术网

python xpath相对路径get<;p>;之前<;br>;

python xpath相对路径get<;p>;之前<;br>;,python,xpath,Python,Xpath,HTML: 您可以尝试以下表达式以获得所需的输出: 欲了解“中国不断变化的贸易结构及其影响”: 要获得“2017年8月25日”: 注意:只有正确定义链接(a)将HTML作为文本而不是图像共享时,这才有效。您需要共享p和td标记的父项,正如Andresson所说,粘贴代码而不是图像这是链接。由于某种原因,我无法复制html文本。。对不起,我试过了,但没用。我刚刚更新并加入了“a”的代码。你能看一下吗?谢谢!您是否使用lxml进行解析?你的代码有什么异常吗

HTML:


您可以尝试以下表达式以获得所需的输出:

  • 欲了解
    “中国不断变化的贸易结构及其影响”

  • 要获得“2017年8月25日”:


  • 注意:只有正确定义链接(
    a

    将HTML作为文本而不是图像共享时,这才有效。您需要共享p和td标记的父项,正如Andresson所说,粘贴代码而不是图像这是链接。由于某种原因,我无法复制html文本。。对不起,我试过了,但没用。我刚刚更新并加入了“a”的代码。你能看一下吗?谢谢!您是否使用
    lxml
    进行解析?你的代码有什么异常吗对我来说很好。。。
    <td>
        <p>China's Changing Trade Structure and its Implications
           <br>
           Kevin Chow, Xiao Hong, John Fu and Sylvia Li
        </p>
        <p>25 August 2017
            <br>
            <a href="/media/eng/publication-and-research/research/research-memorandums/2017/RM13-2017.pdf" target="_blank">Full Paper</a> 
            (PDF File, 465KB)
        </p>
    </td>
    
    for a in response.xpath('//div[@class="prContent"]//a[@href]'):
            url = response.urljoin(a.xpath('@href').extract_first())
            title = extract_text(a.xpath('../../p[1]/text()[1]'))
    
    ../../p[1]/text()[1]
    
    ../../p[2]/text()[1]