0

I'm trying to get the contents of a javascript variable that's on a website when I read it using beautifulsoup4. The javascript variable is involved in calculations before being outputted.

The website that contents all the following javascript is: view-source:https://r6.tracker.network/profile/pc/thelonerankwolf/matches

I want to retrieve matchGroup.data.matches, matchGroup.data.wins, matchGroup.data.kd etc.

<section class="trn-scont__content">
<div class="trn-card" v-for="(matchGroup) in filteredMatches">
<div class="trn-card__content">
<h2 class="trn-title trn-title--normal">
{{ showDate(matchGroup.day) }}
</h2>
<div class="trn-defstats-grid">
<div class="trn-defstat">
<div class="trn-defstat__name">Matches</div>
<div class="trn-defstat__value">{{ matchGroup.data.matches }}</div>
</div>
<div class="trn-defstat">
<div class="trn-defstat__name">Wins</div>
<div class="trn-defstat__value">{{ matchGroup.data.wins }}</div>
</div>
<div class="trn-defstat">
<div class="trn-defstat__name">Kills</div>
<div class="trn-defstat__value">{{ matchGroup.data.kills }}</div>
</div>
<div class="trn-defstat">
<div class="trn-defstat__name">K/D</div>
<div class="trn-defstat__value">{{ matchGroup.data.kd }}</div>
</div>
<div class="trn-defstat">
<div class="trn-defstat__name">MMR Change</div>
<div class="trn-defstat__value">{{ matchGroup.data.mmrDelta }}</div>
</div>
<div class="trn-defstat">
<div class="trn-defstat__name">Time Played</div>
<div class="trn-defstat__value" v-seconds-to-hms="matchGroup.data.timePlayed"></div>
</div>
</div>
</div>

I need help getting the values of the variable for example: Matches= 6

1 Answers1

2

BeautifulSoup is a python library that only parses the HTML. It allows you to get information that is inside of HTML elements(eg text,links,images), but it does not run javascript for you. If you need to view the value of this variable, and it is instantiated in the way you want, then you can simply use a string parser, as seen in this answer. If you need to run the javascript code to get the value of the variable, then you will need to something else. You can use PhantomJS, but my recommendation would be to use selenium. Selenium allows you to control a browser, like Chrome, which will run all of the javascript code on the webpage for you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aiden Grossman
  • 337
  • 5
  • 13