Javascript function to just get all elements from getElementsByClassName












0















First things first, I've looked in a bunch of seemingly related questions that don't directly relate to my problem:



javascript getElementsByClassName from javascript variable



getElementsByClassName doesn't select all my Navigation elements



Javascript: getElementsByClassName not giving all elements



Javascript document.getElementsByClassName not returning all elements



How to change class for all elements retrieved by document.getElementsByClassName



getElementsByClassName vs. jquery



If there is another question that already addresses my specific problem I apologize and please direct me there.



I'm trying to extract opening and current line data from the following page: https://www.sportsbookreview.com/betting-odds/ncaa-basketball/ and it's only returning data for a certain subset of games. The code is below.



convertHalfLines = stringVal => {
let val
let halfLine = false
if (stringVal.substr(-1) === 'u00BD') {
val = parseFloat(stringVal.slice(0,-1))
halfLine = true
} else {
val = parseFloat(stringVal)
}
return halfLine ? val + (Math.sign(val) * 0.5) : val
}

let games = document.getElementsByClassName("_3A-gC")
let gameInfo = Object.keys(games).map(game => {
let teams = games[game].getElementsByClassName("_3O1Gx")
let currentLines = games[game].getElementsByClassName("_3h0tU")

console.log('currentLines',currentLines)

return {
'homeTeam': teams[1].innerText,
'awayTeam': teams[0].innerText,
'homeWagerPct': parseFloat(currentLines[1].innerText),
'awayWagerPct': parseFloat(currentLines[0].innerText),
'homeOpeningLine': convertHalfLines(currentLines[3].getElementsByClassName('_3Nv_7')[0].innerText),
'awayOpeningLine': convertHalfLines(currentLines[2].getElementsByClassName('_3Nv_7')[0].innerText),
'homeCurrentLine': convertHalfLines(currentLines[5].getElementsByClassName('_3Nv_7')[0].innerText),
'awayCurrentLine': convertHalfLines(currentLines[4].getElementsByClassName('_3Nv_7')[0].innerText),
}
})


The code returns data for a certain set of games, which in and of itself is not consistent. Sometimes it returns data for the first six games, sometimes for the first eight, sometimes less or more than these. Is there something I just don't know about JS that I'm missing or is something else going on?










share|improve this question























  • Are you making sure this function is called when the page is rendered? Sounds like it could be related to dynamic js loading. How and where is this code called?

    – mchl18
    Nov 26 '18 at 17:23











  • I'm just opening the page and running it in the console.

    – Jeff
    Nov 26 '18 at 17:26











  • This just makes it very hard to debug but I feel like a lot of errors happenin due to undefined values. I am trying to refactor this somehow.

    – mchl18
    Nov 26 '18 at 17:45











  • I have once written a very specific crawler for a website using casper, maybe it would be a good idea to do this with a framework: github.com/mchl18/casperGrabsch/blob/master/grabsch.js

    – mchl18
    Nov 26 '18 at 17:47













  • I get that there may be errors from undefined values, but what ends up happening is that it eventually doesn't even get the full array of _3Nv_7 items in each game. I'm wondering if maybe it has to do with the fact that a socket connection is opened on the site when the page renders.

    – Jeff
    Nov 26 '18 at 19:53
















0















First things first, I've looked in a bunch of seemingly related questions that don't directly relate to my problem:



javascript getElementsByClassName from javascript variable



getElementsByClassName doesn't select all my Navigation elements



Javascript: getElementsByClassName not giving all elements



Javascript document.getElementsByClassName not returning all elements



How to change class for all elements retrieved by document.getElementsByClassName



getElementsByClassName vs. jquery



If there is another question that already addresses my specific problem I apologize and please direct me there.



I'm trying to extract opening and current line data from the following page: https://www.sportsbookreview.com/betting-odds/ncaa-basketball/ and it's only returning data for a certain subset of games. The code is below.



convertHalfLines = stringVal => {
let val
let halfLine = false
if (stringVal.substr(-1) === 'u00BD') {
val = parseFloat(stringVal.slice(0,-1))
halfLine = true
} else {
val = parseFloat(stringVal)
}
return halfLine ? val + (Math.sign(val) * 0.5) : val
}

let games = document.getElementsByClassName("_3A-gC")
let gameInfo = Object.keys(games).map(game => {
let teams = games[game].getElementsByClassName("_3O1Gx")
let currentLines = games[game].getElementsByClassName("_3h0tU")

console.log('currentLines',currentLines)

return {
'homeTeam': teams[1].innerText,
'awayTeam': teams[0].innerText,
'homeWagerPct': parseFloat(currentLines[1].innerText),
'awayWagerPct': parseFloat(currentLines[0].innerText),
'homeOpeningLine': convertHalfLines(currentLines[3].getElementsByClassName('_3Nv_7')[0].innerText),
'awayOpeningLine': convertHalfLines(currentLines[2].getElementsByClassName('_3Nv_7')[0].innerText),
'homeCurrentLine': convertHalfLines(currentLines[5].getElementsByClassName('_3Nv_7')[0].innerText),
'awayCurrentLine': convertHalfLines(currentLines[4].getElementsByClassName('_3Nv_7')[0].innerText),
}
})


The code returns data for a certain set of games, which in and of itself is not consistent. Sometimes it returns data for the first six games, sometimes for the first eight, sometimes less or more than these. Is there something I just don't know about JS that I'm missing or is something else going on?










share|improve this question























  • Are you making sure this function is called when the page is rendered? Sounds like it could be related to dynamic js loading. How and where is this code called?

    – mchl18
    Nov 26 '18 at 17:23











  • I'm just opening the page and running it in the console.

    – Jeff
    Nov 26 '18 at 17:26











  • This just makes it very hard to debug but I feel like a lot of errors happenin due to undefined values. I am trying to refactor this somehow.

    – mchl18
    Nov 26 '18 at 17:45











  • I have once written a very specific crawler for a website using casper, maybe it would be a good idea to do this with a framework: github.com/mchl18/casperGrabsch/blob/master/grabsch.js

    – mchl18
    Nov 26 '18 at 17:47













  • I get that there may be errors from undefined values, but what ends up happening is that it eventually doesn't even get the full array of _3Nv_7 items in each game. I'm wondering if maybe it has to do with the fact that a socket connection is opened on the site when the page renders.

    – Jeff
    Nov 26 '18 at 19:53














0












0








0








First things first, I've looked in a bunch of seemingly related questions that don't directly relate to my problem:



javascript getElementsByClassName from javascript variable



getElementsByClassName doesn't select all my Navigation elements



Javascript: getElementsByClassName not giving all elements



Javascript document.getElementsByClassName not returning all elements



How to change class for all elements retrieved by document.getElementsByClassName



getElementsByClassName vs. jquery



If there is another question that already addresses my specific problem I apologize and please direct me there.



I'm trying to extract opening and current line data from the following page: https://www.sportsbookreview.com/betting-odds/ncaa-basketball/ and it's only returning data for a certain subset of games. The code is below.



convertHalfLines = stringVal => {
let val
let halfLine = false
if (stringVal.substr(-1) === 'u00BD') {
val = parseFloat(stringVal.slice(0,-1))
halfLine = true
} else {
val = parseFloat(stringVal)
}
return halfLine ? val + (Math.sign(val) * 0.5) : val
}

let games = document.getElementsByClassName("_3A-gC")
let gameInfo = Object.keys(games).map(game => {
let teams = games[game].getElementsByClassName("_3O1Gx")
let currentLines = games[game].getElementsByClassName("_3h0tU")

console.log('currentLines',currentLines)

return {
'homeTeam': teams[1].innerText,
'awayTeam': teams[0].innerText,
'homeWagerPct': parseFloat(currentLines[1].innerText),
'awayWagerPct': parseFloat(currentLines[0].innerText),
'homeOpeningLine': convertHalfLines(currentLines[3].getElementsByClassName('_3Nv_7')[0].innerText),
'awayOpeningLine': convertHalfLines(currentLines[2].getElementsByClassName('_3Nv_7')[0].innerText),
'homeCurrentLine': convertHalfLines(currentLines[5].getElementsByClassName('_3Nv_7')[0].innerText),
'awayCurrentLine': convertHalfLines(currentLines[4].getElementsByClassName('_3Nv_7')[0].innerText),
}
})


The code returns data for a certain set of games, which in and of itself is not consistent. Sometimes it returns data for the first six games, sometimes for the first eight, sometimes less or more than these. Is there something I just don't know about JS that I'm missing or is something else going on?










share|improve this question














First things first, I've looked in a bunch of seemingly related questions that don't directly relate to my problem:



javascript getElementsByClassName from javascript variable



getElementsByClassName doesn't select all my Navigation elements



Javascript: getElementsByClassName not giving all elements



Javascript document.getElementsByClassName not returning all elements



How to change class for all elements retrieved by document.getElementsByClassName



getElementsByClassName vs. jquery



If there is another question that already addresses my specific problem I apologize and please direct me there.



I'm trying to extract opening and current line data from the following page: https://www.sportsbookreview.com/betting-odds/ncaa-basketball/ and it's only returning data for a certain subset of games. The code is below.



convertHalfLines = stringVal => {
let val
let halfLine = false
if (stringVal.substr(-1) === 'u00BD') {
val = parseFloat(stringVal.slice(0,-1))
halfLine = true
} else {
val = parseFloat(stringVal)
}
return halfLine ? val + (Math.sign(val) * 0.5) : val
}

let games = document.getElementsByClassName("_3A-gC")
let gameInfo = Object.keys(games).map(game => {
let teams = games[game].getElementsByClassName("_3O1Gx")
let currentLines = games[game].getElementsByClassName("_3h0tU")

console.log('currentLines',currentLines)

return {
'homeTeam': teams[1].innerText,
'awayTeam': teams[0].innerText,
'homeWagerPct': parseFloat(currentLines[1].innerText),
'awayWagerPct': parseFloat(currentLines[0].innerText),
'homeOpeningLine': convertHalfLines(currentLines[3].getElementsByClassName('_3Nv_7')[0].innerText),
'awayOpeningLine': convertHalfLines(currentLines[2].getElementsByClassName('_3Nv_7')[0].innerText),
'homeCurrentLine': convertHalfLines(currentLines[5].getElementsByClassName('_3Nv_7')[0].innerText),
'awayCurrentLine': convertHalfLines(currentLines[4].getElementsByClassName('_3Nv_7')[0].innerText),
}
})


The code returns data for a certain set of games, which in and of itself is not consistent. Sometimes it returns data for the first six games, sometimes for the first eight, sometimes less or more than these. Is there something I just don't know about JS that I'm missing or is something else going on?







javascript getelementsbyclassname






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 17:20









JeffJeff

657




657













  • Are you making sure this function is called when the page is rendered? Sounds like it could be related to dynamic js loading. How and where is this code called?

    – mchl18
    Nov 26 '18 at 17:23











  • I'm just opening the page and running it in the console.

    – Jeff
    Nov 26 '18 at 17:26











  • This just makes it very hard to debug but I feel like a lot of errors happenin due to undefined values. I am trying to refactor this somehow.

    – mchl18
    Nov 26 '18 at 17:45











  • I have once written a very specific crawler for a website using casper, maybe it would be a good idea to do this with a framework: github.com/mchl18/casperGrabsch/blob/master/grabsch.js

    – mchl18
    Nov 26 '18 at 17:47













  • I get that there may be errors from undefined values, but what ends up happening is that it eventually doesn't even get the full array of _3Nv_7 items in each game. I'm wondering if maybe it has to do with the fact that a socket connection is opened on the site when the page renders.

    – Jeff
    Nov 26 '18 at 19:53



















  • Are you making sure this function is called when the page is rendered? Sounds like it could be related to dynamic js loading. How and where is this code called?

    – mchl18
    Nov 26 '18 at 17:23











  • I'm just opening the page and running it in the console.

    – Jeff
    Nov 26 '18 at 17:26











  • This just makes it very hard to debug but I feel like a lot of errors happenin due to undefined values. I am trying to refactor this somehow.

    – mchl18
    Nov 26 '18 at 17:45











  • I have once written a very specific crawler for a website using casper, maybe it would be a good idea to do this with a framework: github.com/mchl18/casperGrabsch/blob/master/grabsch.js

    – mchl18
    Nov 26 '18 at 17:47













  • I get that there may be errors from undefined values, but what ends up happening is that it eventually doesn't even get the full array of _3Nv_7 items in each game. I'm wondering if maybe it has to do with the fact that a socket connection is opened on the site when the page renders.

    – Jeff
    Nov 26 '18 at 19:53

















Are you making sure this function is called when the page is rendered? Sounds like it could be related to dynamic js loading. How and where is this code called?

– mchl18
Nov 26 '18 at 17:23





Are you making sure this function is called when the page is rendered? Sounds like it could be related to dynamic js loading. How and where is this code called?

– mchl18
Nov 26 '18 at 17:23













I'm just opening the page and running it in the console.

– Jeff
Nov 26 '18 at 17:26





I'm just opening the page and running it in the console.

– Jeff
Nov 26 '18 at 17:26













This just makes it very hard to debug but I feel like a lot of errors happenin due to undefined values. I am trying to refactor this somehow.

– mchl18
Nov 26 '18 at 17:45





This just makes it very hard to debug but I feel like a lot of errors happenin due to undefined values. I am trying to refactor this somehow.

– mchl18
Nov 26 '18 at 17:45













I have once written a very specific crawler for a website using casper, maybe it would be a good idea to do this with a framework: github.com/mchl18/casperGrabsch/blob/master/grabsch.js

– mchl18
Nov 26 '18 at 17:47







I have once written a very specific crawler for a website using casper, maybe it would be a good idea to do this with a framework: github.com/mchl18/casperGrabsch/blob/master/grabsch.js

– mchl18
Nov 26 '18 at 17:47















I get that there may be errors from undefined values, but what ends up happening is that it eventually doesn't even get the full array of _3Nv_7 items in each game. I'm wondering if maybe it has to do with the fact that a socket connection is opened on the site when the page renders.

– Jeff
Nov 26 '18 at 19:53





I get that there may be errors from undefined values, but what ends up happening is that it eventually doesn't even get the full array of _3Nv_7 items in each game. I'm wondering if maybe it has to do with the fact that a socket connection is opened on the site when the page renders.

– Jeff
Nov 26 '18 at 19:53












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53486097%2fjavascript-function-to-just-get-all-elements-from-getelementsbyclassname%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53486097%2fjavascript-function-to-just-get-all-elements-from-getelementsbyclassname%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Futebolista

Jornalista