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 scrape element array - use XPath with element number #154

Closed
pennsong opened this issue Jun 19, 2020 · 1 comment
Closed

How to scrape element array - use XPath with element number #154

pennsong opened this issue Jun 19, 2020 · 1 comment
Labels

Comments

@pennsong
Copy link

First of all, thanks for your great work, I'd like to know how to get the elements array as in chrome console: $$("div.item"), then, i can iterate the arrays to click the items, thanks in advance

@kensoh
Copy link
Member

kensoh commented Jun 23, 2020

Hi Penn, in theory, you can pass back the object through stringified JSON using r.dom(), then parse it back into an object.

However, it is much easier to code and maintain the script, if you use XPath to reference the elements array. The syntax is (XPath)[n] where n is the nth element that matches the XPath provided. r.count() can be used to detect how many elements in total to loop through and process. See eg here.

@kensoh kensoh changed the title how to scrape element array How to scrape element array - use XPath with element number Jun 23, 2020
@kensoh kensoh added the query label Jun 23, 2020
@kensoh kensoh closed this as completed Jun 28, 2020
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

2 participants