Solved

find 'n extract (dealing with HTML)

Posted on 1998-10-01
14
284 Views
Last Modified: 2012-05-04
this is the problem
<META name="Author" content="Jim Smith">
how to find exactly this tag and extract the value of 'content' in a variable
i.e. name="Jim Smith"
     metatag="Author"
0
Comment
Question by:acorp
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 1

Expert Comment

by:zivf
ID: 1437587
what is the problem? extracting text out from the net? searching the file? searching a string inside a string?
please try to be more specific, it seems quite solvable to me.
0
 
LVL 1

Expert Comment

by:zivf
ID: 1437588
consider the above 'answer' as a comment.
sorry.
0
 
LVL 18

Expert Comment

by:deighton
ID: 1437589
acorp, please reject this 'answer' so i can post a proper solution to you.
0
 

Expert Comment

by:AndyJim
ID: 1437590
Just so i get a messag!

0
 

Author Comment

by:acorp
ID: 1437591
ok
the tag must be found in a web page (*.htm,*.html...)
that is loaded withing the program (not from the net, the file is found on the hard drive)
i think i am specific enogh in the question, just try to get it

0
 
LVL 18

Accepted Solution

by:
deighton earned 150 total points
ID: 1437592
'Heres a function to search for your setting within a string
'to search an entire file use

open "text.htm" for input as #1
while not eof(1) and sres = ""
  line input sStr
  sres = find_text(sStr, sYourTag)
wend
 
close #1


Public Function find_text(sString, sTag)

    'Searches a sString for setting sTag
    'e.g. <META name="Author" content="Jim Smith">
    ' find_text(sString,"name") returns Author
   

    Dim i As Integer, iPos As Integer, iStart As Integer

    i = InStr(sString, sTag & "=")
   
    If i <> 0 Then
        iStart = i + Len(sTag) + 1
       
        If Mid(sString, iStart, 1) = """" Then
       
            iPos = iStart + 1
            While Mid(sString, iPos, 1) <> """"
           
                find_text = find_text + Mid(sString, iPos, 1)
                iPos = iPos + 1
       
            Wend
   
        End If
       
    End If


End Function


0
 

Author Comment

by:acorp
ID: 1437593
i can't get this to work
can you make a working sample project of this
if you do i will pay 150 points

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 18

Expert Comment

by:deighton
ID: 1437594
Hi here is an example of my call to the function. - i'd forgotten #1 on my line input
Below it is the text file I used as a test
you need a command button on your form to give the click event.
Any questions please let me know.

Private Sub Command1_Click()

   'EXAMPLE OF A CALL TO THE FUNCTION
   Dim sStr1 As String
   Dim sres1 As String
   Dim sYourTag1 As String
   
   sYourTag1 = "content"
   Open "A:H.HTM" For Input As #1
    While Not EOF(1) And sres1 = ""
      Line Input #1, sStr1
      sres1 = find_text(sStr1, sYourTag1)
    Wend
       
    Close #1
   
    MsgBox sres1

End Sub

TEST DATA in a:h.htm (text format file)

<dummy test line>
<META name="Author" content="Jim Smith">
test dATA


Jim Smith should be displayed in the message box.




0
 

Author Comment

by:acorp
ID: 1437595
az i promised, your 150 points
thanks for the source, it worked great now
0
 

Author Comment

by:acorp
ID: 1437596
OOOPS
there is a problem
sorry
if i have two tags like this
<META name="Author" content="Jim Smith">
<META name="Email" content="jim@smith.net">
how to make one variable with 'Jim Smith' and another with 'jim@smith.net'
sorry to be late for this, just got out of my mind
0
 
LVL 18

Expert Comment

by:deighton
ID: 1437597
'hope this amendment is what you want.

Private Sub Command1_Click()

         'EXAMPLE OF A CALL TO THE FUNCTION
         'I have redesigned this so that each
         'setting is retrieved e.g. for content
         'first setting is in scodes(1) , second in scodes(2)
         
         
         Dim sStr1 As String
         Dim sres1 As String
         Dim sYourTag1 As String
         Dim sCodes(5) As String    'increase this if need more
         Dim icount As Integer
         Dim c
         
         sYourTag1 = "content"
         Open "A:H.HTM" For Input As #1
          While Not EOF(1)
            Line Input #1, sStr1
            sres1 = find_text(sStr1, sYourTag1)
            If sres1 <> "" Then
           
                icount = icount + 1
                sCodes(icount) = sres1
               
            End If
          Wend
             
          Close #1
           
        For c = 1 To icount
          MsgBox "setting " + CStr(c) + " = " + sCodes(c)
        Next

End Sub

0
 

Author Comment

by:acorp
ID: 1437598
yes, but if the tags are in that order
<META name="Email" content="jim@smith.net">
<META name="Author" content="Jim Smith">
not in that:
<META name="Author" content="Jim Smith">
<META name="Email" content="jim@smith.net">
(first the email tag then the author tag i mean)
i wouldn't know which value is for author and which for email
you know what
i will pay you another 200 pionts if you make me a visual basic project
5 text fields (author, email, title, words, description)
on load fill these 5 fields with appropriate values from a text file
when i modify these fields i need to save them back in the file without messing up the other things in it (don't write the common dialog procedure)just explain how to replace the modified tags
the file looks like that
---------------
<dummy test line>
<META name="Author" content="Jim Smith">
<META name="Email" content="Jimmy@jimmi.com">
<META name="Title" content="Yahoo">
<META name="Words" content="these are words">
<META name="Description" content="this is description">
test dATA
----------------
this is it
my email is webmaster@dome.communitech.net

P.S. the program is a Meta tag generator, i need my users to be able to open an HTML file and te values in the tags to be loaded in the fields, then i need to save back that HTML file and the modifications to be in it without having multiple linesin the code of the page

P.S. remember , the project is for another 200 or 400 points (however you want) even 600, 800 or 1000 is possbile
if you have ICQ contact me 3395581
0
 
LVL 18

Expert Comment

by:deighton
ID: 1437599
Hi

As promised I've got that ready now.  I've done some testing and it seems to meet your requirements.  Perhaps you could post a question marked for my attention in this section then I could post the code there for you. Is this ok?  I think 200 points is a fair enough reward for my work on this.

Deighton
0
 

Author Comment

by:acorp
ID: 1437600
ok
i will post in a second
thanks for everything
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now