Results 1 to 9 of 9

Thread: [RESOLVED] Webclient & Regex (Catch String) (One String, no more)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Resolved [RESOLVED] Webclient & Regex (Catch String) (One String, no more)

    Hello all. I'm here again asking stupid questions.
    I don't have really get this but i ask again but i try explain all better.

    Here is a website link and i want catch string from here.
    Look page's source code and find first what starts <td> someword </td>

    I use this code for catch word from page.
    Visual Basic Express 2008 Code:
    1. Imports System.Text.RegularExpressions.Regex
    2.  
    3. Public Class Form1
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         Dim WClient As New Net.WebClient
    6.         Dim WSearch As String
    7.         Dim RX As New System.Text.RegularExpressions.Regex("(?<=<td>).+?(?=</td>)")
    8.         WSearch = WClient.DownloadString("http://itemdb-rs.runescape.com/results.ws?query=Tarromin+seed&price=all&members=")
    9.         MsgBox(RX.Match(WSearch).Value)
    10.     End Sub
    11. End Class

    First td is this:
    PHP Code:
    <td><img src="http://itemdb-rs.runescape.com/2717_obj_sprite.gif?id=5293" alt="Tarromin seed"></td
    So it says me:
    PHP Code:
    <img src="http://itemdb-rs.runescape.com/2717_obj_sprite.gif?id=5293" alt="Tarromin seed"
    Why it can not say market price word "19"
    I want it to say item price.


    Under this what it says me is this.

    PHP Code:
    <td><img src="http://itemdb-rs.runescape.com/2717_obj_sprite.gif?id=5293" alt="Tarromin seed"></td>
    <
    td><a href="http://itemdb-rs.runescape.com/Tarromin_seed/viewitem.ws?obj=5293"Tarromin seed</a></td>
    <
    td>19</td
    Why it cant say this FROM here?
    PHP Code:
    <td>19</td
    Can someone help me.
    Thank you for answers.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Webclient & Regex (Catch String) (One String, no more)

    If not sure if I understand fully what you want, but I think it may be this...?

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim WClient As New Net.WebClient
    3.         Dim WSearch As String
    4.         WSearch = WClient.DownloadString("http://itemdb-rs.runescape.com/results.ws?query=Tarromin+seed&price=all&members=")
    5.         For Each m As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(WSearch, "(?<=<td>).+?(?=</td>)")
    6.             MessageBox.Show(m.Value)
    7.         Next
    8.     End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: Webclient & Regex (Catch String) (One String, no more)

    Actually but i dont want it say more than 3st of your code.

    Only word "19" first and no more.
    <td>19</td> <=====


    Hmm maybe if i tell what i want actually you may understand.


    Go to this address: http://itemdb-rs.runescape.com/resul...e=all&members=
    I want application pickup word 19 after tarromin seed text.
    When they update website and you press button again 19 is another what they put there.

    Msgbox("Current Price")
    Last edited by Zeuz; Aug 7th, 2009 at 02:20 PM.

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Webclient & Regex (Catch String) (One String, no more)

    You only want the "19"?
    vb.net Code:
    1. Dim WClient As New Net.WebClient
    2. Dim WSearch As String
    3. Dim RX As New System.Text.RegularExpressions.Regex("(?<=<td>)\d+?(?=</td>)")
    4. WSearch = WClient.DownloadString("http://itemdb-rs.runescape.com/results.ws?query=Tarromin+seed&price=all&members=")
    5. MessageBox.Show(RX.Match(WSearch).Value)

  5. #5
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Webclient & Regex (Catch String) (One String, no more)

    Try using
    Code:
    Dim RX As New System.Text.RegularExpressions.Regex("(?<=<td>)\d+(?=</td>)")
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  6. #6
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: Webclient & Regex (Catch String) (One String, no more)

    Quote Originally Posted by Zeuz View Post
    Actually but i dont want it say more than 3st of your code.

    Only word "19" first and no more.
    <td>19</td> <=====
    With the example that you have given us, if you really only want the "<td>19</td>" you should use a regular expression like that : "(?<=<td>)\d+?(?=</td>)"

    The "\d" means that you are looking only for digits while the "." means that you are looking for ANY character. If the text between the <td> and </td> tags that you are looking for is always in an Integer format then this regex, also suggested by wild bill in the previous post will do the job, but if the format varies then your regular expression will need some changes.

    Have a look at the links in my signature it might help you build a proper RegEx for your needs.
    Last edited by stlaural; Aug 7th, 2009 at 02:28 PM.
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: Webclient & Regex (Catch String) (One String, no more)

    What the .... Guys. It didn't first worked, now it works.


    Thank you guys.
    So much for all.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: Webclient & Regex (Catch String) (One String, no more)

    Soz multi if this comes as multi message.


    But is here any way to make it show some line like this 19 was.
    Show BY line.

  9. #9
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Webclient & Regex (Catch String) (One String, no more)

    Post your input, and the desired output.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

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