+ Reply to Thread
Results 1 to 4 of 4

Web Scraping

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2011
    Location
    Gig Harbor, WA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Web Scraping

    I am trying to pull the 2014 assessed values from my county assessors website and put them into a spreadsheet. I have the parcel numbers of the properties that I need and I would like to enter the assessed values next to the parcel numbers. The code below is what I have so far. I'm able to get the information from the table on the website to import into the spreadsheet but getting the right cell to copy into the cell next to the right parcel number and loop correctly has stumped me. If there is a better way of doing this where I don't need to import the entire table and then delete it every time let me know. I'm not too familiar with web programming. I have also attached a sample of parcel numbers. Thanks!

    Sub Scrape()
    '
    ' Scrape Macro
    '
    
    '
        For i = 1 To 2
            ThisParcel = ActiveSheet.Cells(i, 1)
            ThisValue = ActiveSheet.Cells(i, 2)
            
        
        With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;http://epip.co.pierce.wa.us/cfapps/atr/epip/taxvalue.cfm?parcel=" & ThisParcel, Destination:=Range("$C$2"))
            .Name = "taxvalue.cfm?parcel=" & ThisParcel
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = xlSpecifiedTables
            .WebFormatting = xlWebFormattingNone
            .WebTables = "10"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            .Refresh BackgroundQuery:=False
            
        End With
        
            Range("F3").Select
            Selection.Copy
            ThisValue.Select
            ActiveSheet.Paste
            Range("C2:J11").Select
            Application.CutCopyMode = False
            Selection.QueryTable.Delete
            Selection.ClearContents
            Range("B2").Select
        
        Next i
        
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Web Scraping

    Try

    Sub Scrape()
    '
    ' Scrape Macro
    '
    
    '
        For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
            ThisParcel = ActiveSheet.Cells(i, 1)
            ThisValue = ActiveSheet.Cells(i, 2)
            
        
            With ActiveSheet.QueryTables.Add(Connection:= _
                "URL;http://epip.co.pierce.wa.us/cfapps/atr/epip/taxvalue.cfm?parcel=" & ThisParcel, Destination:=Range("$C$2"))
                .Name = "taxvalue.cfm?parcel=" & ThisParcel
                .FieldNames = True
                .RowNumbers = False
                .FillAdjacentFormulas = False
                .PreserveFormatting = True
                .RefreshOnFileOpen = False
                .BackgroundQuery = True
                .RefreshStyle = xlInsertDeleteCells
                .SavePassword = False
                .SaveData = True
                .AdjustColumnWidth = True
                .RefreshPeriod = 0
                .WebSelectionType = xlSpecifiedTables
                .WebFormatting = xlWebFormattingNone
                .WebTables = "10"
                .WebPreFormattedTextToColumns = True
                .WebConsecutiveDelimitersAsOne = True
                .WebSingleBlockTextImport = False
                .WebDisableDateRecognition = False
                .WebDisableRedirections = False
                .Refresh BackgroundQuery:=False
                
            End With
        
            ActiveSheet.Cells(i, 2) = Range("F3")
            Columns("C:Z").Clear
                
        Next i
        
    End Sub
    Sub Macro3()
    '
    ' Macro3 Macro
    '
    
    '
        Range("F3").Select
        Selection.Copy
        Range("B1").Select
        ActiveSheet.Paste
        Range("D2:K11").Select
        Application.CutCopyMode = False
        Selection.QueryTable.Delete
        Selection.ClearContents
        Range("B2").Select
    End Sub

  3. #3
    Registered User
    Join Date
    01-14-2011
    Location
    Gig Harbor, WA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Web Scraping

    That works well. One problem though. Parcel numbers in this county are 10 digits long. Often the parcel number starts with a 0. (See example file) When the web query enters the number it is leaving off the 0. The web site does not recognize the parcel numbers so it's skipping the parcel and not returning a value. I know this is a separate issue... but related. Any ideas?

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Web Scraping

    Try

    ThisParcel = Left("0000000000", 10 - Len(ActiveSheet.Cells(i, 1))) & ActiveSheet.Cells(i, 1)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Web Scraping Question
    By vexel77 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-21-2013, 05:21 PM
  2. [SOLVED] Web scraping with xml
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-24-2012, 05:25 AM
  3. Web Scraping Query - Please Help
    By benjison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-16-2012, 08:03 PM
  4. Web scraping
    By mickbarry in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-01-2006, 06:25 AM
  5. Web Screen Scraping
    By scottymelloty in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-29-2005, 09:53 AM

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