Getting certain attribute value using XPath

后端 未结 1 1837
滥情空心
滥情空心 2021-02-08 11:58

From the following HTML snippet:





        
相关标签:
1条回答
  • 2021-02-08 13:04

    Like this:

    data = """<link rel="index" href="/index.php" />
    <link rel="contents" href="/getdata.php" />
    <link rel="copyright" href="/blabla.php" />
    <link rel="shortcut icon" href="/img/all/favicon.ico" />
    """
    
    from lxml import etree
    
    d = etree.HTML(data)
    
    d.xpath('//link[@rel="shortcut icon"]/@href')
    ['/img/all/favicon.ico']
    
    0 讨论(0)
提交回复
热议问题