python - How can I execute JavaScript in Selenium and grab data? -


hello , thank time.

my purpose make parser, follow hundreds of sites , check if site has module (special plugin) or not. main problem, way make sure, a lunch javascript site.

enter image description here

so, don't know how lunch javascript , grap data

for example:

driver = webdriver.chrome('d:\chromedriver_win32\chromedriver')     driver.get("https://lieman.com/") tag = driver.execute_script("document.getelementsbyclassname('arsenal_title')") driver.close() print(tag) 

tag prints none.

can helps me receive data or tell me other way check javascipt

===

def main():     driver = webdriver.chrome('d:\chromedriver_win32\chromedriver')     driver.get("http://redhelper.ru/")     morn = driver.execute_script("return redhlpsettings()")     driver.close()     print(morn)  if __name__ == '__main__':     main() 

you don't need execute javascript, use find_elements_by_class_name(class_name) or find_element_by_class_name(class_name) instead:

tags = driver.find_elements_by_class_name('arsenal_title') 

or

tag = driver.find_element_by_class_name('arsenal_title') 

if need use execute_script other reason, , want value of expression, need return in javascript side:

tags = driver.execute_script("return document.getelementsbyclassname('arsenal_title')") 

update

replace following line:

morn = driver.execute_script("return redhlpsettings()") 

with:

morn = driver.execute_script("return redhlpsettings") 

because redhlpsettings not function. see object in javascript convertd dictionary object in python.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -