1

i want to get value from "value":"165796011" which in data-gbfilter-checkbox

I used

element= driver.find_element_by_css_selector('#widgetFilters > div:nth-child(1) > div.a-row.a-expander-container.a-expander-inline-container > span:nth-child(3)')
print(element.get_attribute('data-gbfilter-checkbox'))

but it give me all data which between data-gbfilter-checkbox bractes

HTML:

<span class="a-declarative" data-action="gbfilter-checkbox" data-gbfilter-checkbox="
{"attribute":"whitelist_categories","value":"165796011","rangeEnd":"","rangeStart":"","filterType":"checkboxes"}">
</span>

i solved it but now( i don't want to write 7 ,I want it with dynamic way)

great I converted the string to list and value number 7, but it's the static way I want to find numbers by the dynamic way ( i don't want to write 7 I want it with dynamic way)

 pages= driver.find_element_by_css_selector('#widgetFilters > div:nth-child(1) > div.a-row.a-expander-container.a-expander-inline-container > div > span:nth-child(25)')

 list= pages.get_attribute('data-gbfilter-checkbox').split('"') print(list[7])
2
  • You will have to parse the string to get what you are looking for. Commented Mar 25, 2020 at 14:20
  • great I converted the string to list and value number 7, but it's the static way I want to find numbers by the dynamic way ( i don't want to write 7 I want it with dynamic way) pages= driver.find_element_by_css_selector('#widgetFilters > div:nth-child(1) > div.a-row.a-expander-container.a-expander-inline-container > div > span:nth-child(25)') list= pages.get_attribute('data-gbfilter-checkbox').split('"') print(list[7]) Commented Mar 25, 2020 at 14:53

1 Answer 1

2

You could parse that into json and then reference the field:

import json
json = json.loads(pages.get_attribute('data-gbfilter-checkbox'))

# the result is a Python dictionary:
print(json["value"])
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.