什么是最安全的方式来提取< title>从使用xpath的HTML文件? [英] What is the safest way to extract <title> from an HTML file using xpath?

查看:71
本文介绍了什么是最安全的方式来提取< title>从使用xpath的HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我当前的xpath代码/ html / head / title



在现实世界的html环​​境中,代码格式通常会被破坏,例如< html> 标记丢失可能会导致异常。所以,我想知道是否有一种安全的方式来提取< title> 标签? (类似于getElementByTagName)

解决方案

// title也许?

Here is my current xpath code "/html/head/title".

But you know, in the real world html environment, the code format usually broken, e.g. <html> tag is missing could cause an exception. So, I would like to know if there's a safe way to extract the <title> tag? (something like getElementByTagName)

解决方案

"//title" perhaps?

这篇关于什么是最安全的方式来提取&lt; title&gt;从使用xpath的HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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