【问题标题】:Parse paragraphs from HTML using lxml使用 lxml 解析 HTML 中的段落
【发布时间】:2011-10-16 15:58:49
【问题描述】:

我是 lxml 的新手,想从给定的 url 中提取 <p>PARAGRAPHS</p><li>PARAGRAPHS</li> 并将它们用于进一步的步骤。

我按照post 中的一个示例,尝试了以下代码,但没有成功:

html = lxml.html('http://www.google.com/intl/en/about/corporate/index.html')
url = 'http://www.google.com/intl/en/about/corporate/index.html'
print html.parse.xpath('//p/text()')

我试图查看lxml.html 中的示例,但没有找到任何使用 url 的示例。

您能告诉我应该使用什么方法吗?谢谢。

【问题讨论】:

    标签: python lxml


    【解决方案1】:
    import lxml.html
    
    htmltree = lxml.html.parse('http://www.google.com/intl/en/about/corporate/index.html')
    
    print htmltree.xpath('//p/text()')
    

    【讨论】:

      猜你喜欢
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-17
      • 2017-12-12
      • 2017-11-17
      • 2012-01-18
      • 2013-12-23
      相关资源
      最近更新 更多