python之获取页面标签的方法
from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup def getTitle(url):
try:
html = urlopen(url)
except HTTPError as e:
return None
try:
bs0bj = BeautifulSoup(html.read(), "html.parser")
title = bs0bj.head.title
except AttributeError as e:
return None
return title title = getTitle("http://www.baidu.com")
if title == None:
print("Title could not be found !")
else:
print(title)
结果如下图所示
END!
python之获取页面标签的方法的更多相关文章
- 用 DOM 获取页面的元素方法集合
document.getElementById('id名') // 获取页面设置指定 id 的元素 document.getElementsByTagName('标签名') ...
- js获取页面url的方法
我们可以用javascript获得其中的各个部分 1, window.location.href 整个URl字符串(在浏览器中就是完整的地址栏) 本例返回值: http://ifisker.com/b ...
- Python 优雅获取本机 IP 方法【转】
转自:https://www.cnblogs.com/lfxiao/p/9672975.html 见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 ...
- Python 优雅获取本机 IP 方法
原文 见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 #!/usr/bin/env python # -*- coding: utf-8 -*- ...
- PHP获取页面执行时间的方法
一些循环代码,有时候要知道页面执行的时间,可以添加以下几行代码到页面头部和尾部: 头部: <?php $stime=microtime(true); 尾部: $etime=microtime(t ...
- Python+Appium 获取 toast 文本值方法的封装
获取toast内容方法封装如下: def get_Toast(self,message): #查找toast值 ''' method explain:查找toast的值,与find_Toast实现方法 ...
- python实现获取身份证号码的方法
记录瞬间 1.号码的结构 公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成.排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码.2.地址码 表示编码 ...
- python中获取执行脚本路径方法
1.sys.path[0]:获取执行脚本目录绝对路径 #每次执行脚本时,python会将执行脚本目录加入PYTHONPATH环境变量中(sys.path获取) #!/usr/bin/python3 i ...
- PHP获取页面执行时间的方法(推荐)
一些循环代码,有时候要知道页面执行的时间,可以添加以下几行代码到页面头部和尾部: 头部:$stime=microtime(true); 尾部: $etime=microtime(true);//获取程 ...
随机推荐
- 数迹学——Asp.Net MVC4入门指南(3):添加一个视图
方法返回值 ActionResult(方法执行后的结果) 例子1 public ActionResult methordName() { return "string"; } 例 ...
- 036. asp.netWeb用户控件之五使用用户控件实现分页数据导航
UserDataPager.ascx用户控件代码: <%@ Control Language="C#" AutoEventWireup="true" Co ...
- php读取sql2000的image字段,被截断的问题
php 存取sql server中类型的照片信息! <?php header("Content-Type:text/html;charset=gb2312"); $url=& ...
- SpringMVC学习系列(4) 之 数据绑定-1
在系列(3)中我们介绍了请求是如何映射到一个action上的,下一步当然是如何获取到请求中的数据,这就引出了本篇所要讲的内容—数据绑定. 首先看一下都有哪些绑定数据的注解: 1.@RequestPar ...
- HackerRank "Kruskal (MST): Really Special Subtree"
Kruskal Algorithm is based on Union-Find - quite intuitive. #include <vector> #include <ios ...
- HackerRank "Prim's (MST) : Special Subtree"
An intuitive Prim algorithm impl. #include <vector> #include <iostream> #include <que ...
- 在Label中显示一段文字
Let’s create a new Xamarin.Forms PCL solution, named Greetings, using the same process described abo ...
- string引用类型解惑
先上代码: string b = "123"; private void Form1_Load(object sender, EventArgs e) { Test(b); Mes ...
- (String) 压缩String
e.g. aaabbcccc 返回a3b2c4 public static String compressString(String str) { StringBuilder sb=new S ...
- 远程登录,无法加载explorer
最近不知什么缘故,远程登录服务器时,无法登录到桌面了,只能用mstsc.exe /admin方式登录或者登录后按(CTRL+ALT+END)进入任务管理,新建运行explorer.exe才能登录到桌面 ...