Results 1 to 22 of 22

Thread: Searching for text

  1. #1

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219

    Searching for text

    Hi, In my program it gets the webpages html. I now need to get certain information from it. i need all the words between "> and </a>. You see it goes in a pattern. theres like 100 names on each webpage. I need the words in red. The variable that has the webpages inofrmation is sdata can anyone help me? I think i need to use a regualr expression but which one and how? Thanks


    <tr>
    <td width="13%" bgcolor="#494949" align="center">302</td>
    <td width="45%" bgcolor="#494949"><a href="profile.php?id=471916">jerkass</a></td>
    <td width="19%" bgcolor="#494949">32,755</td>
    <td width="23%" bgcolor="#494949">$4,225,896</td>
    <td width="23%" bgcolor="#494949">$0</td>
    </tr>

    <tr>
    <td width="13%" align="center">303</td>
    <td width="45%"><a href="profile.php?id=1005793">Laser28</a></td>
    <td width="19%">32,686</td>
    <td width="23%">$0</td>
    <td width="23%">$31,160,354</td>
    </tr>

    <tr>
    <td width="13%" bgcolor="#494949" align="center">304</td>
    <td width="45%" bgcolor="#494949"><a href="profile.php?id=869471">Mephew</a></td>
    <td width="19%" bgcolor="#494949">32,534</td>
    <td width="23%" bgcolor="#494949">$717,989</td>
    <td width="23%" bgcolor="#494949">$100,000,000</td>
    </tr>
    -Rob

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    To learn more about regular expressions try here:
    http://www.fawcette.com/vsm/2003_01/...na/default.asp

    Although it would be something close to this:
    VB Code:
    1. 'if inputStr is the text you posted
    2.         Dim pattern As String = "\>\w+\<\/a\>"
    3.         Dim reg As New System.Text.RegularExpressions.Regex(pattern)
    4.         Dim mcol As System.Text.regularexpressions.MatchCollection = reg.Matches(inputStr)
    5.         For Each m As System.Text.RegularExpressions.Match In mcol
    6.             MsgBox(m.Value)
    7.         Next
    Last edited by Edneeis; Sep 16th, 2003 at 10:34 AM.

  3. #3

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    Its not working for me. But let me give you somemore details. The webpage that i need the information from is in the variable url . I need to take the information i got and put it in listbox1. In your code i dont understand where all the output goes. Is it in one of the variables?
    -Rob

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If the text is in a variable called 'url' and you want to fill a listbox then it would be like this:

    VB Code:
    1. Dim pattern As String = "\>\w+\<\/a\>"
    2.         Dim reg As New System.Text.RegularExpressions.Regex(pattern)
    3.         Dim mcol As System.Text.regularexpressions.MatchCollection = reg.Matches(url)
    4.         For Each m As System.Text.RegularExpressions.Match In mcol
    5.             listbox1.items.add(m.Value)
    6.         Next

    Also what does 'Its not working for me' mean? Do you get an error? What?

  5. #5

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    i cant understand why it is not working. when i click the button nothing happens. Im sorry url is not text. It is the actuall link to the page. The text variable is sData but i dont know if i did it the right way. This is what i have:
    VB Code:
    1. stream = New IO.StreamReader(wc.OpenRead(url))
    2.         sData = stream.ReadToEnd
    3.  
    4.         Dim pattern As String = "\>\w+\<\/a\>"
    5.         Dim reg As New System.Text.RegularExpressions.Regex(pattern)
    6.         Dim mcol As System.Text.regularexpressions.MatchCollection = reg.Matches(sData)
    7.         For Each m As System.Text.RegularExpressions.Match In mcol
    8.             ListBox1.Items.Add(m.Value)
    9.         Next
    10.     End Sub
    By the way thank you for your help it is greatly apreciated because i have a deadline by tommorw at 5'o Clock
    Last edited by VBGangsta; Sep 16th, 2003 at 08:16 PM.
    -Rob

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Set a breakpoint in there and make sure sData is the kind of text you posted.

  7. #7

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    What exaclty is a break point and where do i put?. Sry for all the questions. SData is the variable that holds the downloaded Html(in text form) That is what i posted.
    Last edited by VBGangsta; Sep 16th, 2003 at 08:56 PM.
    -Rob

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    A breakpoint is a location that is set to have your code stop so you can debug. It looks like a red dot on the left margin by the code in the IDE. If sData contains the same text as you posted or text in the same format then it will work.

  9. #9

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    ok im watching what is happening at the breakpoints. Ill tell u what happens in a sec.
    -Rob

  10. #10

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    I have no idea why this isnt working. I was looking at the breakpoints but i really didnt see a porblem. But when i click the button to intiate those events nothing is displayed in the listbox. I checked your pattern and that is correct to find the names, well very close. so i dont know what to do. Can u help me? THanks you
    -Rob

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What can I do to help? Post your project if you want and I'll look at it.

  12. #12

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    id rather not post it on here but can I email it to you? my email is [email protected] Thank you very much
    -Rob

  13. #13

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    OK i think I found thee problem. I set a breakpoints where SData(the variable holding the downloaded html text) was. At the bottom of my environment i saw and excel type window and i saw sdata then to the right i saw the html. So i right clicked the html text and copied and pasted it to a word documeant and saw that the html that it is holding is not all of it. its only the top part that doesnt even have the information i need so I am guessing thats why nothing is showing up in the listbox. Something must be wrong with the downloaded html text commands. Think you could help? Thanks
    -Rob

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What is the URL you are using so I can test it?

  15. #15

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    -Rob

  16. #16
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I get a SQL error on the page and not much comes up which would mean you wont get the data you are looking for. SO maybe its not your code after all.

  17. #17

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    No thats the url but I just realized that u need to log in before u can see that page. So I put all the html in a text file.
    Attached Files Attached Files
    Last edited by VBGangsta; Oct 5th, 2003 at 10:26 AM.
    -Rob

  18. #18
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well that doesn't help considering you said the problem was getting the page. Maybe the trouble is that when you try and retrieve the page it isn't logging you in. You should see if the html you are retrieveing has the sql error in it.

  19. #19

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    no, the reason that u could not see that link is because you need to be loged in to beable to view that page. For now I will skip that problem and move on to retriving the info i need form the url. Lets say that the html is in the sData variable. I have made a pattern or whatevr u call it, >(\S+)</a but i do not know how to go about doing this.
    -Rob

  20. #20
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well if you can get the data into sData from the URL then you are all set. Are you asking how to implement the code I gave you? If so here is an example that uses the text file you posted.

  21. #21

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    O my god!!! Edneeis you are the BEST!!!!!!!!! You dont know how long i have had this problem. THANK YOU SO MUCH!!!!!
    -Rob

  22. #22

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    uhh oo..its me again. I have tried evrything but i can not get html from a webite. Any ideas??
    -Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width