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 select element in drop-down list #566

Open
Su-Da-Ko opened this issue Jan 22, 2024 · 0 comments
Open

How to select element in drop-down list #566

Su-Da-Ko opened this issue Jan 22, 2024 · 0 comments

Comments

@Su-Da-Ko
Copy link

I want to select element in drop-down list, like "Select" method in Selenium, but only get result before select.
How I modify code below?
(Run in google colab)

from requests_html import AsyncHTMLSession
url = "https://hoge.com"

session = AsyncHTMLSession()
r = await session.get(url)
await r.html.arender(timeout=60, keep_page=True)

select = r.html.find("select")
if len(select) > 0:
    print(select[0])  // <Element 'select' ... >

option = r.html.find("option")
print(option)  // [<Element 'option' value='1' selected='selected'>, <Element 'option' value='1'>, <Element 'option' value='2'>, ... ]

f = await r.html.page.select('select', "3")
print(f)  // ["3"]

option = r.html.find("option")
print(option)  // [<Element 'option' value='1' selected='selected'>, <Element 'option' value='1'>, <Element 'option' value='2'>, ... ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant