I'm using Selenium WebDriver to scrape information from many web-pages. I wonder if it's possible to select multiple children elements by CSS selector. The HTML structure looks like:
<section id="education">
<div class="degree">
<h3 class="school"> School1 </h3>
<p class="year"> 2002-2008 </p>
</div>
<div class="degree">
<h3 class="school"> School2 </h3>
</div>
</section>
In this case, I want to select the school names with their corresponding year ranges. But if I simply use:
driver.find_elements_by_css_selector('section[id="education"] div[class="school"]')
driver.find_elements_by_css_selector('section[id="education"] p[class="year"]')
I will get two lists: [School1, School2]
and ['2002-2008']
, and I won't be able to tell which school corresponds to year range '2002-2008'
. So, is it possible to combine the corresponding school name and year range together? If there are other ways to get around it, it would be helpful too.