How to select all tags with selenium and python -


<a title="citrate of magnesia consumers" href="/cdi/citrate-of-magnesia-solution.html"> <b>citrate of magnesia</b> 

i'm trying pull data medication website , how select text in <b></b> tags? because that's text want.

i've tried *//a[@b]and doesn't work.

assuming trying rely on preceding a element, use following-sibling, example:

//a/following-sibling::b 

python code:

b = driver.find_element_by_xpath("//a/following-sibling::b") print(b.text) 

if want multiple b tags having a preceding element:

for b in driver.find_elements_by_xpath("//a/following-sibling::b"):     print(b.text) 

solution provided after chatting:

from selenium import webdriver selenium.webdriver.common.by import selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec  driver = webdriver.chrome() driver.get("http://www.drugs.com/drug-class/laxatives.html?condition_id=&generic=0&sort=rating&order=desc")   # wait table list load table = webdriverwait(driver, 10).until(ec.presence_of_element_located((by.css_selector, "table.data-list")))  b in table.find_elements_by_css_selector("tr td > a[href] > b"):     print(b.text) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -