3

I'm using webbrowser to crawl some pages and am most comfortable / familiar with jQuery & CSS selectors to navigate the DOM.

I was trying to read around but wasn't sure if this is possible, or will do what I want it.

In the console I can run something like:

x = $('.job-container').children()

and it will return me the list of children. I can then scroll through them and get what I'm looking for.

I tried this in Selenium

from selenium import webdriver
browser = webdriver.Chrome()
url = "some_url"
browser.get(url)
browser.execute_script("$('.job-container').children()[0]")

However its not returning anything.

I'm less familiar with how to navigate the DOM using xPath, so I thought I'd try jquery w/ CSS selectors first and if that doesn't work, try to pick up xpath.

Is there a way to use jQuery inside execute_script? Or will it not do what I want it to do?

1 Answer 1

2

Try to execute something like

browser.execute_script("return $('.job-container').children()[0]")

or

browser.execute_script("return document.querySelector('.job-container').childNodes[0]")
Sign up to request clarification or add additional context in comments.

1 Comment

that was it, it wasn't returning anything. thank you!

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.