1

To give you a quick background on what I'm trying to do - I'm trying to scrape odds from multiple bookies and exchanges through excel VBA through a macro that would trigger every second minute to refresh the prices..

While I'm comfortable with the referencing a cell element (or even a row element and then indexing the cell (as with my code below), some sites (or even just some pages within sites) don't seem to reference any IDs I'm too green to HTML and scrapping in general to work around this - This is an example of the problem I'm encountering (exploded out to the last):

enter image description here

Now, if there's an alternative to appIE.document.getElementById() I'm all for it because the button class below has more info for me then just the 3.1 price, such as the liquidity (in the above example there's €1079 available to lay on this exchange at that price) I presume this would involve absolute referencing down to the "bet button price" and "bet button size" classes?

The code I have at present involves declaring and assigning the appIE:

Dim appIE as Object
Set appIE = CreateObject("internetexplorer.application")

Declaring the element and assigning it:

Dim targetElement As Object
Set targetElement = appIE.document.getElementById("xxxx")

Storing the value as a double

Dim myValue as Double
myValue = targetElement.innerHTML

and then populating the target cell with myValue

Any and all help would be greatly appreciated - If you need more detail, just let me know.

6
  • There are other methods on the HTMLDocument object that you can investigate: getElementsByClassName, getElementsByName, getElementsByTagName, querySelector and querySelectorAll. Commented Jan 31, 2017 at 0:59
  • Thanks @RobinMackenzie - Just quickly, is there a property like getElementsByClassName([Call name]).Price to return the price property (2.68 in the above example) and getElementsByClassName([Call name]).Size that would return €1079 etc..? - I'm in work currently so, for obvious reasons, I can't be playing around with it at the moment - I'll play around with it further when I get home either way. Thanks for you help! Commented Jan 31, 2017 at 9:40
  • You still have to work with the DOM and figure out which element has the data item you want. If you start with the button you still have to work down a few levels. It's a tree with branches where you navigate each branch... Commented Jan 31, 2017 at 11:58
  • @RobinMackenzie Thanks - Understood (I think!) but given that the "branches" have a standardised naming convention, couldn't I declare the subclasses' names as strings (in the above example it'd be "bet-button-price" (as, say sPrice_String) and and "bet-button-size" and then reference them as something like getElementsByClassName([Class name here]).class(sPrice_String).innerHTML? Commented Jan 31, 2017 at 12:14
  • Look at querySelector - msdn.microsoft.com/en-us/library/cc288169(v=vs.85).aspx Commented Jan 31, 2017 at 12:27

1 Answer 1

1

I'd recommend querySelector Some links: |W2C queryselector| Microsoft queryselector|

This uses CSS selector syntax which is very common now in Javascript because it is how JQuery navigates the DOM.

Chrome is really helpful in that its developer tools give the CSS expression for each element as you move mouse around. I think your screenshot is from Chrome.

If you look really really closely at your screenprint image you will see the CSS selector to get to the cell so "td.bet-buttons.lay-cell.ng-scope.first-lay-cell" This given on the footer bar and also on a tooltip style label

Ah heck, I've gone and circled in red the expressions. Here you go

enter image description here

UPDATE: actually there is an inaccuracy here the full path is given by the complete footer text (i.e. the whole line), the flying tooltip gives the identifier that nhavigates an element given its parent (i.e. just one part of the path).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.