VBA scrapping of USPTO website

ScooterNorm

New Member
Joined
Feb 25, 2024
Messages
22
Office Version
  1. 2016
Platform
  1. Windows
Excel Version (Office 2016)

Excel Environment (desktop, Windows)

Knowledge Level - Intermediate level

I'm trying to scrape off the USPTO website. When I do a manual search the URL is: https://tsdr.uspto.gov and I enter a serial number (i.e. 79349658), press the status button and the search is executed and the results are returned.

The resulting URL of the search page is:

https://tsdr.uspto.gov/#caseNumber=...TION&caseType=DEFAULT&searchType=statusSearch

When I try to execute this with VBA, it returns the tsdr.uspto.gov web page, not the result of the search. Any idea what I'm doing wrong?

Here's the code,

Sub Test()
Dim ht As HTMLDocument
Dim IE As InternetExplorer

Set IE = New InternetExplorer
IE.Visible = True
IE.navigate ("Trademark Status & Document Retrieval" & _
"&caseSearchType=US_APPLICATION" & _
"&caseType=DEFAULT" & _
"&searchType=statusSearch")

Do Until IE.readyState = READYSTATE_COMPLETE And IE.Busy = False
DoEvents
Loop

Set ht = IE.document

'IE.Quit

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Here's an alternative method...

VBA Code:
Sub test()

    'Set a reference (VBE > Tools > References) to the following libraries:
    '   1) Microsoft XML, v6.0
    '   2) Microsoft HTML Object Library

    Dim xmlReq As MSXML2.ServerXMLHTTP60
    Dim htmlDoc As MSHTML.HTMLDocument
    Dim strURL As String
    Dim strResp As String
    
    Set xmlReq = New MSXML2.ServerXMLHTTP60
    
    Set htmlDoc = New MSHTML.HTMLDocument
    
    strURL = "https://tsdr.uspto.gov/statusview/sn79349658"
    
    With xmlReq
        .Open "GET", strURL, False
        .send
        If .Status <> 200 Then
            MsgBox "Error " & .Status & ":  " & .statusText
            Exit Sub
        End If
        strResp = .responseText
    End With
    
    htmlDoc.body.innerHTML = strResp
    
    'etc
    '
    '
    
    Set xmlReq = Nothing
    Set htmlDoc = Nothing

End Sub

Hope this helps!
 
Upvote 1
Yep, seems fine to me. When I run the following, it runs successfully, without and errors...

VBA Code:
    Set elems1 = htmlDoc.getElementsByClassName("double table")
    
    For i = 0 To elems1.Length - 1
            Set elems2 = elems1(i).getElementsByClassName("value")
            Debug.Print elems2(0).innerText
    Next i

By the way, with regards to your declaration...

VBA Code:
Dim elems1, elems2, elems3 As Object

...only elems3 is declared as Object, the others are declared as Variant. To declare all as Object...

VBA Code:
Dim elems1 as Object, elems2 as Object, elems3 As Object
 
Upvote 1
Solution
Try...

VBA Code:
IE.navigate "https://tsdr.uspto.gov/" & _
    "#caseNumber=79349658" & _
    "&caseSearchType=US_APPLICATION" & _
    "&caseType=DEFAULT&searchType=statusSearch"

Hope this helps!
 
Upvote 0
Thanks Dominic,
Yes, that's what I tried. It returns the Search screen as if you entered tsdr.uspto.gov
My post is messed up and I can't figure out how to edit my post.
 
Upvote 0
Actually, in your code, you didn't include the case number, as I did in mine...
 
Upvote 0
Actually, in your code, you didn't include the case number, as I did in mine...
actually I did include the serialno. That’s one of the things messed up on post which I can’t figure out how to fix. But my VBA code has the serialno.
 
Upvote 0
When I try my code, it returns the status result.

If you don't see an "Edit" option/button, you don't have the option to edit your post. In that case, try posting the navigate portion again, but this time make sure that you post them between code tags. You should see a button that looks like this </> on the toolbar above the message area.
 
Upvote 0
When I try my code, it returns the status result.

If you don't see an "Edit" option/button, you don't have the option to edit your post. In that case, try posting the navigate portion again, but this time make sure that you post them between code tags. You should see a button that looks like this </> on the toolbar above the message area.
Humm when I tried it, it returned the tsdr.uspto.gov page, not the search page result.
Thanks for the tip on using the </> I'll try it here again and post my code:

VBA Code:
Sub Test()
    Dim IE As InternetExplorer

    Set IE = New InternetExplorer

    IE.Visible = True

    IE.navigate ("https://tsdr.uspto.gov/#caseNumber=79349658" &_
                 "&caseSearchType=US_APPLICATION" & _
                 "&caseType=DEFAULT" & _
                 "&searchType=statusSearch")

    Do Until IE.readyState = READYSTATE_COMPLETE And IE.Busy = False
        DoEvents
    Loop

End Sub

Is that the code you tried?
Also, I'm using Excel Version (Office 2016) on Excel Environment (desktop, Windows).

Thanks again for your suggestions,
 
Upvote 0
Excel Version (Office 2016)

Excel Environment (desktop, Windows)

Knowledge Level - Intermediate level

I'm trying to scrape off the USPTO website. When I do a manual search the URL is: https://tsdr.uspto.gov and I enter a serial number (i.e. 79349658), press the status button and the search is executed and the results are returned.

The resulting URL of the search page is:

Trademark Status & Document Retrieval

When I try to execute this with VBA, it returns the tsdr.uspto.gov web page, not the result of the search. Any idea what I'm doing wrong?

Here's the code,

Sub Test()
Dim ht As HTMLDocument
Dim IE As InternetExplorer

Set IE = New InternetExplorer
IE.Visible = True
IE.navigate ("Trademark Status & Document Retrieval" & _
"&caseSearchType=US_APPLICATION" & _
"&caseType=DEFAULT" & _
"&searchType=statusSearch")

Do Until IE.readyState = READYSTATE_COMPLETE And IE.Busy = False
DoEvents
Loop

Set ht = IE.document

'IE.Quit

End Sub
I’d like to add another point. When I to execute the code with VBA

VBA Code:
IE.navigate ("https://tsdr.uspto.gov/" & _
            "#caseNumber=79349658" & _
            "&caseSearchType=US_APPLICATION" & _
            "&caseType=DEFAULT" & _
            "&searchType=statusSearch")

The case number shows up in the search box and in addition a small x appears on the right hand side of the case number when I navigate to the case number data entry. The same x does not show up when I manually navigate to the page.
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,970
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top