Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to create windows form Sql for get page source website and parse content. complete description homepage: parse this source.

HTML
<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:

C#
Brand       URL
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


and 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.
Posted
Updated 5-Sep-16 22:08pm
Comments
Karthik_Mahalingam 5-Sep-16 5:28am    
not clear, Please provide more info
mohsen07 5-Sep-16 6:36am    
For the home page, created by the brand and the brand name and URL are entered.
For the brand (for example, Acer adapter plate), the brand, the Aspire ... to be created,In this same page, the C 120 model table are to be created and the name and address of the store.
Inside Page C-120 model, description and capabilities is stored in the table or in a text file.
Karthik_Mahalingam 5-Sep-16 6:44am    
give some example
mohsen07 5-Sep-16 7:43am    
for u :
http://www.laptop-power-adapters.co.nz

Karthik_Mahalingam 5-Sep-16 7:44am    
in the above url what information you need?

1 solution

Here is the code for a UDF that you can use

SQL
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,@Start,@Length,'')
SET @Start = CHARINDEX('<',@HTMLText) SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
END
RETURN LTRIM(RTRIM(@HTMLText))
END
GO


Follow SQL SERVER - 2005 - UDF - User Defined Function to Strip HTML - Parse HTML - No Regular Expression - Journey to SQL Authority with Pinal Dave[^]
 
Share this answer
 
Comments
mohsen07 5-Sep-16 10:22am    
It is possible to explain the codes?
I used but the error:)
thank you for answer
NaibedyaKar 5-Sep-16 10:55am    
What error did you get. Did you get error while creating the function or executing the function?

Once you create the UDF, then call it as below
SELECT dbo.[udf_StripHTML] ('<div id="naver">
- <ul id="naverlist">
-- <li class="overbrand" class="navhome">HOME</li>
- <li>Acer</li>
<li class="navspecial">Contact Us</li>
</ul>
</div>') AS OutputText

The code basically checks for the angle brackets start "<" and end ">". After that it removes the text inside this. Thus by removing the html code and just keeping the plain text.
mohsen07 6-Sep-16 1:48am    
thanks for help. its ok but in output text in one line but i want acer and url in two column.please help me:
brand name--------------url
acr----------------- http://.....htm

thanks
mohsen07 6-Sep-16 2:05am    
very thank you.
only error in script tag because in content is text=... also i want to delete Unnecessary content as home or contact us وAlso out on a table with two columns with brand names and Url are displayed next to each name as example of my question.
The possibility that addresses both pages are displayed at the outlet?
thank you for help.
mohsen07 6-Sep-16 2:10am    
It is possible to write an explanation for each line command

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900