Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read() from multi items - use count() and for loop to select nth occurence #231

Closed
BeanHhb opened this issue Mar 30, 2021 · 4 comments
Labels

Comments

@BeanHhb
Copy link

BeanHhb commented Mar 30, 2021

Hi @kensoh
Thanks to you Guide book, I try RPA-Python for some simple demo.
I dont know how to opera when I want to get each text from multi items which have same feature.
Such as:
a = r.count('.gl-i-wrap strong i') // a= 30
b = r.read('.gl-i-wrap strong i') // b only get the text from first item

Please show me the correct way to get all text. Tkx

@kensoh
Copy link
Member

kensoh commented Mar 30, 2021

Hi @BeanHhb, oh you can do the following. Lemme know if you run into issues!

You are using CSS selector, . is class. Normally I use XPath in below eg. I think in CSS you'll use :nth-child(item).

total_items = r.count('//*[@class="gl-i-wrap strong i"]')
for item in range(1, total_items + 1):
    value = r.read('(//*[@class="gl-i-wrap strong i"])[' + str(item) + ']')

For XPath, (XPath)[n] means the nth occurrence of an item. This is a more elaborate example from the API Reference - #24

@kensoh kensoh added the query label Mar 30, 2021
@kensoh kensoh changed the title How to read() from multi items How to read() from multi items - use count() and for loop to select nth occurence Mar 30, 2021
@BeanHhb
Copy link
Author

BeanHhb commented Mar 31, 2021

Tks, Kensoh.
i turn to use XPath as the way you provide.

@BeanHhb BeanHhb closed this as completed Mar 31, 2021
@vigraton
Copy link

How do I define total_items?

@kensoh
Copy link
Member

kensoh commented Feb 4, 2023

Hi @vigraton sorry I had a typo! I've updated above example. total_items is derived from using r.count()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants