selenium webdriver in python -
so i'm trying make script in python uses selenium webdriver open , login website called marketsworlds , retrieve market value of stock. have script able open , login page. cant figure out how capture/get market value , have print out. used inspect element find class:
<p class="market_value"> </p>
in between open , close brackets inspect element displays market value, changes. tried setting driver.find_element_by_class("market_value") variable , printing variable. print out of " @ object 0x" , ever comes after x. way return displays?
if have use selenium navigation, such on javascript-heavy sites, suggest acquiring page source , using html parser extract data want.
beautifulsoup great choice of parser. example:
html = driver.page_source soup = beautifulsoup(html) # *all* 'p' tags specified class attribute. p_tags = soup.findall('p',{'class':'market_value'}) p in p_tags: print p.text
this should print screen text contained in <p>
tags class market_value
. hard give specifics without knowing exact page source, however.
however, if you're determined use strictly selenium, can find these elements by:
# *all* 'p' tags specified class attribute. elements = driver.find_elements_by_class_name('market_value') element in elements: print element.text # or # *single* 'p' tag specified class attribute. element = driver.find_element_by_class_name('market_value') print element.text
Comments
Post a Comment