本文介绍了如何在SQL中创建选择HTML标签内部文本的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想创建用于获取页面源网站和解析内容的Windows窗体。完整描述主页:解析此来源。 < div id = naver > - < ul id = naverlist > - < li class = overbrand class = navhome > < a href = http://www.laptop-power-adapters.co.nz > HOME < / a > < / li > - < li > < a href = http://www.laptop-power-adapters.co.nz/acer-laptop-power-adapters.htm > Acer < / a > < / li > < li class = navspecial > < a href = http ://www.laptop-power-adapters.co.nz/contact.htm target = _ blank > 与我们联系< / a > < / li > < / ul > < / div > 解析后创建BrandTBL并保存acer`url和ACR: 品牌网址 Acer http: // www.laptop-power-adapters.co.nz/acer-laptop-power-adapters.htm ASUS http: // www.laptop-power-adapters.co.nz/asus-laptop-power-adapters.htm 获取acer`url的源代码并解析acer`url。 in宏碁的页面源:按名称MOdelTBL系列创建表格,在表格中保存c720和c720`url。 谢谢。 我尝试了什么: 我在网上搜索但我的问题没有解决。解决方案 以下是您可以使用的UDF代码 CREATE FUNCTION [dbo]。[udf_StripHTML]( @ HTMLText VARCHAR (MAX)) RETURNS VARCHAR (MAX) AS BEGIN DECLARE @ Start INT DECLARE @ End INT DECLARE @ Length INT SET @ Start = CHARINDEX(' <', @HTMLText ) SET @ End = CHARINDEX(' >', @HTMLText ,CHARINDEX(' <', @HTMLText )) SET @ Length =( @ End - @ Start )+ 1 WHILE @ Start > ; 0 AND @ End > 0 AND @ Length > 0 BEGIN SET @HTMLText = STUFF( @ HTMLText , @开始, @ Length ,' ') SET @ Start = CHARINDEX(' <', @HTMLText ) SET @ End = CHARINDEX(' >', @HTMLText ,CHARINDEX(' <', @HTMLText )) SET @ Length =( @ End - @ Start ) + 1 END RETURN LTRIM(RTRIM( @ HTMLText )) END GO 关注 SQL SERVER - 2005 - UDF - 用户自定义函数剥离HTML - 解析HTML - 没有正则表达式 - 使用Pinal Dave访问SQL权限 [ ^ ] I want to create windows form Sql for get page source website and parse content. complete description homepage: parse this source.<div id="naver"> - <ul id="naverlist"> -- <li class="overbrand" class="navhome"><a href="http://www.laptop-power-adapters.co.nz">HOME</a></li> - <li><a href="http://www.laptop-power-adapters.co.nz/acer-laptop-power-adapters.htm">Acer</a></li> <li class="navspecial"><a href="http://www.laptop-power-adapters.co.nz/contact.htm" target="_blank">Contact Us</a></li> </ul> </div>after parse create BrandTBL and save acer`url and ACR:Brand URLAcer http://www.laptop-power-adapters.co.nz/acer-laptop-power-adapters.htmASUS http://www.laptop-power-adapters.co.nz/asus-laptop-power-adapters.htmand get source code of acer`url and parse acer`url.in page source of acer : create table by name MOdelTBL series and in Table , Save c720 and c720`url.Thanks.What I have tried:I am searching in web But My problem is not resolved. 解决方案 Here is the code for a UDF that you can use CREATE FUNCTION [dbo].[udf_StripHTML] (@HTMLText VARCHAR(MAX))RETURNS VARCHAR(MAX)ASBEGINDECLARE @Start INTDECLARE @End INTDECLARE @Length INTSET @Start = CHARINDEX('<',@HTMLText) SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText)) SET @Length = (@End - @Start) + 1 WHILE @Start > 0AND @End > 0AND @Length > 0BEGINSET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')SET @Start = CHARINDEX('<',@HTMLText) SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))SET @Length = (@End - @Start) + 1ENDRETURN LTRIM(RTRIM(@HTMLText))ENDGOFollow SQL SERVER - 2005 - UDF - User Defined Function to Strip HTML - Parse HTML - No Regular Expression - Journey to SQL Authority with Pinal Dave[^] 这篇关于如何在SQL中创建选择HTML标签内部文本的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 17:45