+ Reply to Thread
Results 1 to 10 of 10

Search HTML source code for text

Hybrid View

  1. #1
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Search HTML source code for text

    Hi folks.

    I need to check a website daily to see if a link has been updated. If it has been updated, the beginning of the link changes to a different date. Example: today link is www.10212009dave.com and tomorrow link may be www.10222009dave.com. Lets say the link is on www.gugg.com. The link does not change everyday, but I think a good way to see if it has been updated is to search through the source code in the html for that link.

    Thus I would put www.10212009dave.com into cell A1 and tell excel to search the source code on www.gugg.com, and if the contents of cell A1 is NOT found, I'd display a message box stating the link has been updated.

    Could anyone help me find a way to do this?

    OR

    Can anyone suggest a better way to check if the link has been updated?

    Thanks!
    Last edited by davegugg; 10-22-2009 at 02:51 PM.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search HTML source code for text

    Hello Dave,

    This macro will tell you if the link has been updated using the contents of cell "A1". You can change the site to want you want. It is in red font.
    Sub CheckLink()
    
      Dim IEapp As Object
      Dim IEdoc As Object
      Dim Href As String
      Dim Res As Variant
      Dim Site As String
      
        Site = "www.google.com"
        Href = Range("A1")
        
        Set IEapp = CreateObject("InternetExplorer.Application")
        IEapp.Navigate Site
        
          While IEapp.Busy
            DoEvents
          Wend
          
          Set IEdoc = IEapp.Document
          
          For Each Item In IEdoc.Links()
            Res = InStr(1, Item.outerhtml, Href)
            If Res Then
               MsgBox "Link has Not Changed"
               GoTo Finish
            End If
          Next Item
          
          MsgBox "Link has been Updated."
          
    Finish:
        Set IEapp = Nothing
        Set IEdoc = Nothing
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Search HTML source code for text

    That seems like what I need, but it is not working. I tried it with the site I am accessing, and also with google and neither worked. I'll post a link of the google example. Not sure if it matters, but IEdoc is set to "[Object]" and Res ends up being 0 each time.
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search HTML source code for text

    Hello Dave,

    The workbok now contains 2 links. One in "A1" and another in "A2". I checked "A1" and it is no longer on the Google page. The link in "A2" is valid. I added a button to call the macro. When the macro is run from the VBIDE, the message box appears while Internet Explorer is active. The message box appears behind Excel while Internet Explorer is active. The message box now is displayed after IE is closed. Here is the updated code. These changes have been made to the attached workbook,
    Sub CheckLink()
    
      Dim IEapp As Object
      Dim IEdoc As Object
      Dim Href As String
      Dim Msg As String
      Dim Res As Variant
      Dim Site As String
      
        Site = "www.google.com"
        Href = Range("A2")
        
        Set IEapp = CreateObject("InternetExplorer.Application")
        IEapp.Navigate Site
        
          While IEapp.Busy
            DoEvents
          Wend
          
          Set IEdoc = IEapp.Document
          
          For Each Item In IEdoc.Links()
            Res = InStr(1, Item.outerhtml, Href)
            If Res Then
               Msg = "Link has Not Changed"
               GoTo Finish
            End If
          Next Item
          
          Msg = "Link has been Updated."
          
    Finish:
        IEapp.Quit
        Set IEapp = Nothing
        Set IEdoc = Nothing
        MsgBox Msg
        
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Search HTML source code for text

    Does it matter that the link I'm searching for ends in .pdf? Try it with http://www.mgic.com/pdfs/71-6799_sifi_lpmi_oct09.pdf in A2 and http://www.mgic.com/rates/ratecards.html as the site being searched.

    Example below:
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search HTML source code for text

    Hello Dave,

    If the link address exists with in the web page HTML source code, the macro will find it. I have checked the page source code for the link the you provided and it doesn't exist.

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Search HTML source code for text

    You are right. I searched through the source code manually and found instead of writing out http://www.mgic.com/pdfs/71-6799_sifi_lpmi_oct09.pdf, it just has ../pdfs/71-6799_sifi_lpmi_oct09.pfd.

    I can make that work, I'll just have to look at the source code every time it changes to find the correct path. Since it only changes about twice a year, that shouldn't be a problem.

    Thanks Leith you've been very helpful.
    Props

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Search HTML source code for text

    Leith, as discussed:
    Attached Files Attached Files

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search HTML source code for text

    Hello Dave,

    I have run it several times and the results are consistent, even with searches being done with the wireless network running. My system is using Explorer 6.0, perhaps it is a version difference causing the problem.

  10. #10
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Search HTML source code for text

    Ok, thanks so much for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1