0

Hey I need to search for variable data in a console from a page source

The data will be shown like this:

"data":[13,17]

It will vary a lot with the amount of units inside the table. I have tried out several RE expressions, but the closest I have come to a result, is with a fixed amount of units.

self.driver.get("website.com")
apidata = self.driver.page_source
print(apidata)
datasetbasic = re.search('"data":[[0-99,0-99]+', apidata)
print(datasetbasic)

Instead of having it as a fixed amount, how do I capture anything that is inside the data table?

Before you ask, I cannot use xpath or any other selenium calls to capture this data directly from the webpage (I think), because the element is from a graph, where the data is only visible in the actual console.

Any help is appreciated

FlendtDK
  • 11
  • 1
  • Escape the first `[`, and `[0-99,0-99]+` is the same as `[,0-9]+`, capture that part, use `'"data":\[([,0-9]+)'` and then check if there is a match and print Group 1 value: `if datasetbasic: print(datasetbasic.group(1))` – Wiktor Stribiżew Apr 23 '20 at 19:58
  • Actually, the two links at the top of your question should be enough to solve the issue. – Wiktor Stribiżew Apr 23 '20 at 20:10
  • It works! Thank you very much. I want to understand the code as well, so why does this "[,0-9]+" work? Is it because ,0-9 defines all numeric values and seperators, or? – FlendtDK Apr 23 '20 at 20:16
  • See https://stackoverflow.com/questions/1545751/how-to-back-reference-inner-selections-in-a-regular-expression/1553171#1553171, use http://regex101.com to debug regexps and see what they match. – Wiktor Stribiżew Apr 23 '20 at 20:21

0 Answers0