Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

find 'n extract (dealing with HTML)

Posted on 1998-10-01
14
Medium Priority
?
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 600 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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 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