🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.vbasic
Article #104589

Re: vb6 - wyciągnięcie linków z html

#104589
From: Zbigniew Bratko
Date: Thu, 08 Apr 2010 16:49
84 lines
3834 bytes
Użytkownik "ChrissP." <krzyszp@-tnij-.poczta.onet.-tnij-.pl> napisał w
wiadomości news:hpklti$p80$1@news.onet.pl...

[...]

> Trochę chyba niejasno napisałem.
> Kontrolka zwraca mi zmienną tekstową z zawartością maila w html. W niej
> taki string:
>
> <HEAD><TITLE>rmpHTMLEdit</TITLE><BASE href=http://>
> <META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK
> href="" type=text/css rel=stylesheet>
> <META content="MSHTML 6.00.6000.16850" name=GENERATOR></HEAD>
> <BODY>
> <P>Dear Mr Krzysztof Jagodzinski</P>
> <P><IMG
> src="file:///C:/Documents%20and%20Settings/krzyszp/My%20Documents/Downlo
> ads/w0168131_normal.jpg"><IMG
> src="file:///C:/Documents%20and%20Settings/krzyszp/My%20Documents/Projec
> ts/RTA-Multiuser/Logo.jpg"></P></BODY>
>
> Ja rozdzielam go na poszczególne linie bazując na "</P>", następnie
> potrzebuję wrzucić do tablicy poszczególne linki do obrazków:
>
> C:/Documents%20and%20Settings/krzyszp/My%20Documents/Downloads/w0168131_
> normal.jpg

[...]

Nie rozdzielaj w/m nowej linii, tylko usuń wszystkie znaki nowej linii
i rozdziel tekst w/m Tagu <img src="
jako znak końca odnośnika szukaj ciągu "> jako znak końca Tagu img.

Coś w tym rodzaju:

' sHTML jest ciągiem znaków, a nie tablicą !!!
'__________________________________________
Private Function GetLinks(sHTML As String) As String
Dim lInStrStart As Long
Dim lInStrEnd As Long
Dim sLinks As String
Dim lLenStart As Long
Dim lLenEnd As Long
Dim i As Long
' w Html-u tak dokładnie musi być zapisany Tag <img src="
' brak spacji lub więcej niż jedna spacja
' skutkować będzie błędnym odczytem
Const MY_START As String = "<img src="
'Const MY_START As String = "<img src = "
Const MY_END As String = """" & ">"

' wytnij wszystkie znaki końca linii, bo może być np. <img
' src=
' lub w innym miejscu może być znak nowej linii
sHTML = Replace(sHTML, vbNewLine, "", , , vbBinaryCompare)

lLenStart = Len(MY_START)
lLenEnd = Len(MY_END)

lInStrStart = InStr(1, sHTML, MY_START, vbTextCompare)

Do Until lInStrStart = 0
   lInStrEnd = InStr(lInStrStart, sHTML, MY_END)
   If lInStrEnd > 0 Then
      sLinks = sLinks & Mid$(sHTML, lInStrStart + lLenStart, _
               lInStrEnd - lInStrStart - lLenStart) & ";"
      lInStrStart = InStr(lInStrEnd, sHTML, MY_START, vbTextCompare)
   End If
   DoEvents
Loop

If Len(sLinks) > 0 Then GetLinks = Left$(sLinks, Len(sLinks) - 1)

End Function

Resztę szczegółów dopracuj sobie.
Pisane w Accessie, ale stałe i funkcje są chyba zgodne.


-- 
Pozdrowienia
BraZby
http://www.accessfaq.pl/
Technical Details
Message-ID: <hpl1el$lb0$1@inews.gazeta.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail
References: <hpk9dr$eoa$1@news.onet.pl> <d6c4b207-9485-4b5b-ab71-f57d4152f44e@8g2000yqz.googlegroups.com> <hpkcku$o66$1@news.onet.pl> <57fd66ae-908f-422a-8d2e-fe71510a36da@q23g2000yqd.googlegroups.com> <hpklti$p80$1@news.onet.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail
From: "Zbigniew Bratko" <brazby1DelTo@op.pl>
Newsgroups: pl.comp.lang.vbasic
Subject: Re: vb6 - wyciągnięcie linków z html
Date: Thu, 8 Apr 2010 18:49:25 +0200
Organization: "Portal Gazeta.pl -> http://www.gazeta.pl"
Lines: 85
Message-ID: <hpl1el$lb0$1@inews.gazeta.pl>
References: <hpk9dr$eoa$1@news.onet.pl> <d6c4b207-9485-4b5b-ab71-f57d4152f44e@8g2000yqz.googlegroups.com> <hpkcku$o66$1@news.onet.pl> <57fd66ae-908f-422a-8d2e-fe71510a36da@q23g2000yqd.googlegroups.com> <hpklti$p80$1@news.onet.pl>
NNTP-Posting-Host: pj007.multi-play.net.pl
Mime-Version: 1.0
X-Trace: inews.gazeta.pl 1270745365 21856 91.142.206.154 (8 Apr 2010 16:49:25 GMT)
X-Complaints-To: usenet@agora.pl
NNTP-Posting-Date: Thu, 8 Apr 2010 16:49:25 +0000 (UTC)
X-Antivirus-Status: Clean
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5843
X-User: brazby
X-Antivirus: avast! (VPS 100408-0, 2010-04-08), Outbound message
X-MSMail-Priority: Normal
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit