使用javascript和python selenium来获得所需的值

2024-04-19 17:27:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从https://www.facebook.com/public/nitin-solanki页获取一些数据。我可以获得除这些标签之外的所有值(这些标签的值我已经得到)

有人建议我使用Javascript executer和python来获得这些标签,我添加了这个标签,但是它们不打印任何值,也不给出错误。在

Studied atLives inFrom

driver.get("https://www.facebook.com/public/nitin-solanki")         
wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "mbm")))
    for s in driver.find_elements_by_css_selector('.mbm.detailedsearch_result'):
        result = {}
        v =  s.find_element_by_css_selector('.fsm.fwn.fcg')
        x = v.find_elements_by_class_name('fbProfileBylineLabel')
        for y in x:
           #print y.text #this should give me label like lives in, studied at but does not
            #js line which does not give any result
            print x.executeScript("return arguments[0].childNodes[0].nodeValue;");
            print driver.executeScript("return arguments[0].childNodes[0].nodeValue;",x);
            #js ends
            z = y.find_elements_by_tag_name('a')
            for a in z:
                print a.text #I want to get label for this value along with it

Tags: inhttpscomforbyfacebookwwwdriver