logo elektroda
logo elektroda
X
logo elektroda

Downloading Data from Website via VBA Macro: No Element ID/Name, GetElements Solution

Montana310 6426 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17447548
    Montana310
    Level 5  
    Please help. I have to download data from the website, but unfortunately no element on the page has its own ID, name, etc. Therefore, the use of .getElementsById or .getElementsByTagName is probably out of the question (or at least I don't know how to connect it). Below I am attaching a photo of the script from the website.
    I am asking for help if you can play specific data or transfer everything to Excel so that I can "work it" further. I will be grateful if someone has already written code that downloaded such data and will make it available for inspection.

    Downloading Data from Website via VBA Macro: No Element ID/Name, GetElements Solution
  • ADVERTISEMENT
  • #2 17447694
    rufek90
    Level 25  
    I don't know much about VBA, but html elements can be downloaded e.g. by tag name or class. Here 'document api': https://developer.mozilla.org/en-US/docs/Web/API/Document
    It is worth paying attention to the querySelector and querySelectorAll methods: https://developer.mozilla.org/pl/docs/Web/API/Document/querySelector which allows you to very precisely define what elements you are looking for. Thanks to this, perhaps we can do without some loops by elements
  • ADVERTISEMENT
  • #3 17447730
    mistrzszymon1
    Level 24  
    What is generating these tables ?? Can you paste this code instead of a photo? /
  • #4 17447837
    Montana310
    Level 5  
    mistrzszymon1 wrote:
    What is generating these tables ?? Can you paste this code instead of a photo? /


    Generally, the code is generated by a program that gives us order data. Unfortunately, I do not have the code now, because I only made printscreen what the script of the page looks like. Maybe tomorrow I will be able to do it.
  • ADVERTISEMENT
  • #5 17447893
    mistrzszymon1
    Level 24  
    Most likely, the program can be set to add a class or an id :)

    Added after 2 [minutes]:

    If not, as rufek90 querySelector wrote, and matching what you need :)
    A colleague forgot to mention what he wants to learn from this document :)
  • ADVERTISEMENT
  • #6 17447899
    rufek90
    Level 25  
    I recommend running the development console and testing the selectors there to find the right one. Some example: document.querySelector ('. DataWidget tr: nth-of-type (3) td: nth-of-type (2)');
    Instead of nth-of-type, you can use querySelectorAll and select the appropriate items from the array. You need to familiarize yourself with the basics of using the console in the browser.

    If you throw in all the sample html and say which fields you are interested in, I will try to help with the selection
  • #7 17448550
    kinggustav
    Level 27  
    You have to get each item by id, either bulk by class or tag type (good for tables). You will probably have to mix these methods to get where you need to go. It all depends on the construction of this website.
    Look for "vba excel ie automation" in googles. There are a lot of materials, but specifically in your case it takes ... a lot of time. And you must have it or buy it, because time is money.
  • #8 17451903
    WRadek
    Level 23  
    And if you are truly desperate, you can download the entire source of the page as text and then work on the text.
    I was able to do everything I wanted to get out like that.

Topic summary

The discussion revolves around downloading data from a website using a VBA macro when no HTML elements have identifiable IDs or names. Participants suggest using methods like `querySelector` and `querySelectorAll` to target elements by class or tag name. They emphasize the importance of understanding the website's structure and recommend testing selectors in the browser's development console. Alternatives include downloading the entire page source as text for further processing. The conversation highlights the need for a tailored approach depending on the specific HTML structure of the target website.
Summary generated by the language model.
ADVERTISEMENT