我如何使用Python检索网页的页面标题? [英] How can I retrieve the page title of a webpage using Python?

查看:146
本文介绍了我如何使用Python检索网页的页面标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Python检索网页的页面标题(标题html标记)?

使用 lxml 执行此类任务。您也可以使用美丽的照片

  import lxml.html 
t = lxml.html.parse(url)
print t.find(.// title)。text


How can I retrieve the page title of a webpage (title html tag) using Python?

解决方案

I'll always use lxml for such tasks. You could use beautifulsoup as well.

import lxml.html
t = lxml.html.parse(url)
print t.find(".//title").text

这篇关于我如何使用Python检索网页的页面标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆