和查询网址title keywords description的信息一样
可自动辨别网站的编码将网站的信息查询出来
asp 获取网址的title keywords description
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- ChatGPTᴼᴾᴱᴺᴬᴵ 2023-01-17 17:17关注
在 ASP 中获取网站的 title、keywords、description 信息可以使用第三方库或自行编写代码来实现。一种常用的方法是使用正则表达式来匹配页面源代码中的相应信息。
为了能够自动辨别网站的编码,可以使用第三方库来解析页面源代码,例如 HtmlAgilityPack。
下面是一个简单的示例代码:
Dim html As String Dim title As String Dim keywords As String Dim description As String html = GetHTML("http://example.com") title = GetTitle(html) keywords = GetKeywords(html) description = GetDescription(html) Function GetHTML(ByVal URL As String) As String Dim objXMLHTTP As Object Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") objXMLHTTP.Open "GET", URL, False objXMLHTTP.Send GetHTML = objXMLHTTP.responseText Set objXMLHTTP = Nothing End Function Function GetTitle(ByVal html As String) As String Dim pattern As String pattern = "(?i)<title[^>]*>\s*(.*?)\s*</title>" GetTitle = GetMatch(html, pattern) End Function Function GetKeywords(ByVal html As String) As String Dim pattern As String pattern = "(?i)<meta\s+name=""keywords""\s+content=""(.*?)""" GetKeywords = GetMatch(html, pattern) End Function Function GetDescription(ByVal html As String) As String Dim pattern As String pattern = "(?i)<meta\s+name=""description""\s+content=""(.*?)""" GetDescription = GetMatch(html, pattern) End Function Function GetMatch(ByVal html As String, ByVal pattern As String) As String Dim objRegExp As Object Set objRegExp = New RegExp objRegExp.Pattern = pattern objRegExp.IgnoreCase = True objRegExp.Global = True If objRegExp.Test(html) Then GetMatch = objRegExp.Execute(html)(0).SubMatches(0) Else GetMatch = "" End If Set objRegExp = Nothing End Function
上面的代码使用正则表达式来匹配页面中的 title、keywords、description 信息。获取到页面信息后,可以使用这些信息进行后续的处理。
请注意,上面的代码只是一个简单的示例,在实际应用中可能需要进行更多的处理。例如,确保网站编码正确解析,处理网站挂掉或者网络连接异常的情况。
另外,使用第三方库可能更加方便,如使用HTML Agility Pack来解析页面信息。
解决 无用评论 打赏 举报
悬赏问题
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号
- ¥50 安装pyaudiokits失败
- ¥15 计组这些题应该咋做呀
- ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
- ¥15 让node服务器有自动加载文件的功能
- ¥15 jmeter脚本回放有的是对的有的是错的
- ¥15 r语言蛋白组学相关问题
- ¥15 Python时间序列如何拟合疏系数模型