Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 51
  1. #16
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62

    Quote Originally Posted by Edgar View Post
    I couldn't send a header to make this url return a different date format:
    https://www.bing.com/packagetracking...ex&FORM=PCKTR1
    However, using my VPN, I was able to see that the date format changes according to the IP. So using a VPN will let you return a good date.

    The second website sends a series of http requests while loading the data, so our http request procedure will only bring the initial site before it loads stuff. For this kind of workflow, a browser automation is better. However, I tested that it fails quite often because of it being internet explorer (or maybe I sent too many requests too fast). You could however use Selenium or Puppeteer for that. Or use another method. Having the VPN wouldn't be a bad idea, bing can give you a good date if you use an IP outside the US. It would save you a lot of time.

    In order to get the text with class "deliveryDateTextBetween", you would use:
    Document.getElementsByClassName("deliveryDateTextB etween")(0).innerText in VBA
    Document.getElementsByClassName("deliveryDateTextB etween")[0].innerText in JS

    Don't give up with VBA, though. There are other approaches to take. Maybe you can open the IE window, then grab it using shell and get its document element to inspect it.

    Thanks so much again, Edgar, for taking the time to look at this problem of mine. I will try the VBA code you suggested.

  2. #17
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Tried using FedEx URL and get "Object variable or With block variable not set" error on:
    Debug.Print res.getElementsByClassName("deliveryDateTextBetwee n")(0).innerText


    I can:
    Debug.Print req.responseText
    Delivery info does not show in the output.


    So how does VBA capture the info as done with: right click on the website page and select "Inspect" I get a window showing the HTML code, I think. When I right click on the Elements window and select "Copy" then "Copy outerHTML"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    June7, you mentioned the reason yourself for the fedex url to not work with a simple http request. This one requires browser automation because their app sends additional http requests that help come up with the result. Trying to catch all those requests and faking them from VBA is not worth it, better to just use some browser automation. Also, for getElementsByClassName to work, there must be a document to inspect, you got the error because there was none. It was not set. Once you get access to the document element, you can query it easily using the posted snippet.

    The following code did work on my end, but you need to not spam the server. Try to use it once every minute at least.

    Code:
    Option Compare Database
    Option Explicit
    
    Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    
    Sub getFedexDate2()
        Dim ie As Object
        Set ie = CreateObject("InternetExplorer.Application")
        
        ie.navigate "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=581190049992&cntry_code=us&locale=en_US"
        ie.Visible = True
        
        Do Until Not ie.Busy And ie.ReadyState = 4
            DoEvents
        Loop
    
        Sleep 3000
        
        Dim deliveryDate As Object
        Set deliveryDate = Nothing
        
        Do While deliveryDate Is Nothing
            On Error Resume Next
            Set deliveryDate = ie.Document.getElementsByClassName("deliveryDateTextBetween")(0)
            On Error GoTo 0
        Loop
        
        Debug.Print deliveryDate.innerText
        
        ie.Quit
        Set ie = Nothing
    End Sub
    What it does is open ie and navigate to the url. Then, using shell, get the window you opened and attempt to set the html element until it appears. It also waits 3 seconds for good measure. I hope it gives you some results.
    Please click on the ⭐ below if this post helped you.


  4. #19
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    That last code works for me, even with MS opening another tab amd a warning message that IE is out of support.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #20
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Quote Originally Posted by Welshgasman View Post
    That last code works for me, even with MS opening another tab amd a warning message that IE is out of support.
    Excellent news! I tested it on Access 2016, you use 2007, right?

    The following lines can probably be commented out and it should still work, but it's good to be cautious.
    Code:
        Do Until Not ie.Busy And ie.ReadyState = 4
            DoEvents
        Loop
    
        Sleep 3000
    Last edited by Edgar; 09-23-2023 at 01:18 AM. Reason: extra info
    Please click on the ⭐ below if this post helped you.


  6. #21
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Yes Edgar, I am on 2007. It is enough for my needs.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #22
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    What the... I noticed I posted the version that doesn't use a shell window. Anyway, if anyone's wondering, here's that snippet too.
    Code:
    Sub getFedexDate()
        Dim ie As InternetExplorer
        Set ie = New InternetExplorer
        
        ie.navigate "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=581190049992&cntry_code=us&locale=en_US"
        ie.Visible = True
        
    '    Sleep 3000
        
        Dim sh As Object
        Set sh = CreateObject("shell.application")
    
        Dim deliveryDate As Object
        Set deliveryDate = Nothing
        
        Do While deliveryDate Is Nothing
            On Error Resume Next
            Set deliveryDate = sh.windows.Item(0).Document.documentElement.getElementsByClassName("deliveryDateTextBetween")(0)
            On Error GoTo 0
        Loop
        
        Debug.Print deliveryDate.innerText
        
        ie.Quit
        Set ie = Nothing
    End Sub
    Hey, that confirms it, they both work as long as you don't spam the server.
    Please click on the ⭐ below if this post helped you.


  8. #23
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    I needed to add MS Internet Controls to get that one to work.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #24
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    You're right, Gasman, that's on my reference list, I don't remember adding it though. Something added it.
    Please click on the ⭐ below if this post helped you.


  10. #25
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    Quote Originally Posted by June7 View Post
    Tried using FedEx URL and get "Object variable or With block variable not set" error on:
    Debug.Print res.getElementsByClassName("deliveryDateTextBetwee n")(0).innerText


    I can:
    Debug.Print req.responseText
    Delivery info does not show in the output.


    So how does VBA capture the info as done with: right click on the website page and select "Inspect" I get a window showing the HTML code, I think. When I right click on the Elements window and select "Copy" then "Copy outerHTML"

    That's my question. Is there a way for VBA to capture the data in the outerHTML. I manually copied the outerHTML to Word. It's over 900 pages but the information I want is in there.

  11. #26
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    This works great, Edgar. Thanks so much for your expertise.

  12. #27
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    For some reason "Sleep 3000" doesn't compile. I will have to research that.

  13. #28
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Did you include the Sleep API code? If you did and are using 64-bit Access, it will need updating using PtrSafe
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  14. #29
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Glad it works for Euler, crashed Access for me.
    I already have Microsoft Internet Controls reference library selected.
    Sleep 3000 does not compile for me either.

    I added DoEvents and the page eventually loads after error message "Fedex is not responding due to a long-running script." but the data is never pulled. VBA is frozen (infinite loop?). I have to kill with Task Manager.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #30
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    Yes, I found the API code and entered "PtrSafe" so it would work. Now, it works just fine, though a little slow compared to the original code.
    I deeply appreciate the efforts of everyone who spent their time with this. Thank you very much.

Page 2 of 4 FirstFirst 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query from Website
    By ajmac in forum Forms
    Replies: 2
    Last Post: 07-30-2020, 07:24 AM
  2. Replies: 0
    Last Post: 12-06-2016, 11:28 AM
  3. Access on Website
    By Kevo in forum Access
    Replies: 6
    Last Post: 07-08-2015, 11:23 AM
  4. Web Scraping with MS Access 2010
    By Fabricio Sanches in forum Import/Export Data
    Replies: 1
    Last Post: 02-26-2012, 04:33 PM
  5. Scraping text from web into Access
    By abbeyainscal in forum Import/Export Data
    Replies: 5
    Last Post: 04-10-2010, 01:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums