Get Data from a Website

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    #1

    Get Data from a Website

    Access 2002 - Windows XP Home SP3
    I want to get some data from a website. Currently I select the desired area of the webpage and copy to Clipboard. This selected area contains text and 2 imbedded images, a .jpg (~7K) and a .gif.
    When I cntl-V (Paste) into an Access textbox, the 2 images are gone. Also gone are the stuff the designers of the webpage use to put the various pictures, colors, etc. on the webpage. I know nothing about this.
    I have to return to the web page and separately SaveAs the .jpg image, and note which .gif image is shown, so I can manually enter using a combobox.

    I want to do automatically-
    1) Get the text without the imbedded images.
    2) Determine which (of about 20) .gif is present. This may be in the image name, if I could see it.
    3) Determine if .jpg is 1 of 3, and if not, SaveAs & strFileName, where I can generate strFileName after analyzing text in 1).

    I notice that pasting the entire webpage into WordPad shows different results in the area I'm interested in than selecting that area from the webpage and pasting only that into WordPad.

    Can someone point me toward info on how to do this?
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Hello OB,

    Have you tried HTML Scraping. A member has some code here that you should be able to modify. I haven't tried the code myself but have a look at it or read some articles on HTML Scraping for more details,




    cheers,

    Originally posted by OldBirdman
    Access 2002 - Windows XP Home SP3
    I want to get some data from a website. Currently I select the desired area of the webpage and copy to Clipboard. This selected area contains text and 2 imbedded images, a .jpg (~7K) and a .gif.
    When I cntl-V (Paste) into an Access textbox, the 2 images are gone. Also gone are the stuff the designers of the webpage use to put the various pictures, colors, etc. on the webpage. I know nothing about this.
    I have to return to the web page and separately SaveAs the .jpg image, and note which .gif image is shown, so I can manually enter using a combobox.

    I want to do automatically-
    1) Get the text without the imbedded images.
    2) Determine which (of about 20) .gif is present. This may be in the image name, if I could see it.
    3) Determine if .jpg is 1 of 3, and if not, SaveAs & strFileName, where I can generate strFileName after analyzing text in 1).

    I notice that pasting the entire webpage into WordPad shows different results in the area I'm interested in than selecting that area from the webpage and pasting only that into WordPad.

    Can someone point me toward info on how to do this?

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by OldBirdman
      Access 2002 - Windows XP Home SP3
      I want to get some data from a website. Currently I select the desired area of the webpage and copy to Clipboard. This selected area contains text and 2 imbedded images, a .jpg (~7K) and a .gif.
      When I cntl-V (Paste) into an Access textbox, the 2 images are gone. Also gone are the stuff the designers of the webpage use to put the various pictures, colors, etc. on the webpage. I know nothing about this.
      I have to return to the web page and separately SaveAs the .jpg image, and note which .gif image is shown, so I can manually enter using a combobox.

      I want to do automatically-
      1) Get the text without the imbedded images.
      2) Determine which (of about 20) .gif is present. This may be in the image name, if I could see it.
      3) Determine if .jpg is 1 of 3, and if not, SaveAs & strFileName, where I can generate strFileName after analyzing text in 1).

      I notice that pasting the entire webpage into WordPad shows different results in the area I'm interested in than selecting that area from the webpage and pasting only that into WordPad.

      Can someone point me toward info on how to do this?
      Couldn't the entire HTML Source Code be Pasted into Word where it could easily be examined or Saved as Text Only where the entire File can be opened in Access, and each Line analyzed in turn?

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        I cannot get the code referred to by HTML scraping to work. I get a message
        Compile error:
        User-defined type not defined
        on Line 2
        Code:
        Dim webBrowser As webBrowser
        Apparently Access 2002 does not know what a webBrowser is. I don't understand the code, and can't figure it out if I can't run it. I learn from new examples by stepping thru the code, but this code won't start for me.

        Couldn't the entire HTML Source Code be Pasted into Word where it could easily be examined or Saved as Text Only where the entire File can be opened in Access, and each Line analyzed in turn?
        I've never tried automation, which I believe this involves. However, I did open Word and paste the entire webpage into it. It took about 45 seconds (hourglass) to do the paste. Even repeated pastes. The clear in preparation for another paste took 10 seconds.
        Loading Word has its own time penalty. I don't know enough about Word to create a command button to read the text. So here is a whole new subject to investigate, but I think not now.
        As I look at the Word page after the paste, I still can't find the .jpg picture address to download and save. The .gif name is embedded in the image frame, and that name would be enough for my purposes, if I knew enough to get to it. But the time cost is excessive, and I still would have to return to IE and "SaveAs..." the image.
        I currently paste my selected area of the webpage into an unbound textbox, assign to a string variable, and scrape it. This gets me all the info I need except the .gif name and the ability to save the .jpg image.
        So far, my steps are:
        Code:
        1) Press "New Record" button in my Access (myDB)
        2) Alt+Tab to Microsoft Internet Explorer (IE) 
           and select the correct Tab and/or navigate
           to the desired web page
        3) Select desired section of web page
        4) Cntl+V to copy to clipboard
        5) Alt+Tab to return to myDB
        6) Press command button "Paste from Website"
        7) If MsgBox "GIF not determined", clear with "OK"
        8) Alt+Tab to return to IE
        9) RightClick .jpg Image and select "Save Picture As..."
              Cntl+V to paste file name into dialog
                  (this was generated in step 6
                   and copied to clipboard)
              Press "Enter" or click "Save" to save image
        10) Mentally note .gif displayed
        11) Cntl+Tab to return to myDB
        12) If 7) displayed msg, Click combobox and 
              select row to note .gif displayed
        13) Click command button to record that an image
              was actually acquired & saved.
        Although this seems like a clumsy set of instructions, replacing with these doesn't seem to help.
        Code:
        1) same as 1) above
        2) same as 2) above
        3) Cntl+A Select the entire web page
        4) Cntl+C Copy web page to clipboard
        5) Alt+Tab to Word
        6) Cntl+A Select anything in Word
        7) Cntl+P Paste selected from step 4,
            overwriting anything already in Word
        8) Alt+Tab to myDB
        9) Press command button "Scrape from Word"
        10) <<I still have no .jpg image, not sure steps here>>
        What I am aiming for (and may not get to) is:
        Code:
        1) same as 1) above
        2) same as 2) above
        3) Alt+Tab to myDB
        4) Press command button "Get from Website"

        Comment

        Working...