0

I am trying to get some data from https://www.facebook.com/public/nitin-solanki page. I can get all values apart from

Studied at Lives in From

These three label. Value for this label I could get using

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
            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

What i want to do is create dictionary

{'Studied_at' : 'Gujarat University', 'Lives_in': 'Ahmedabad, India', 'From' : 'Ahmedabad, India'}

for these three values.

nlper
  • 2,297
  • 7
  • 27
  • 37

1 Answers1

1

You can get the nodevalue of the element using Javascript Childnodes property

//try in browser console
    document.getElementsByClassName("fbProfileBylineLabel")[0].childNodes[0].nodeValue;//Studied at

    document.getElementsByClassName("fbProfileBylineLabel")[1].childNodes[0].nodeValue;//Lives in

    document.getElementsByClassName("fbProfileBylineLabel")[2].childNodes[0].nodeValue;//From

pseudocode

v =  s.find_element_by_css_selector('.fsm.fwn.fcg')
        x = v.find_elements_by_class_name('fbProfileBylineLabel')
        for y in x:
            //Example in java(sry not to familiar with python)
           JavascriptExecutor js = (JavascriptExecutor) driver;
         String s= (String)js.executeScript("return arguments[0].childNodes[0].nodeValue;",x);

            z = y.find_elements_by_tag_name('a')

Hope this helps you.Kindly get back if you have any doubts

Vicky
  • 2,999
  • 2
  • 21
  • 36
  • will there be JS executor in python too? – nlper Jul 28 '15 at 06:26
  • yes it is there...refer the links http://selenium-python.readthedocs.org/en/latest/api.html http://stackoverflow.com/questions/7794087/running-javascript-in-selenium-using-python – Vicky Jul 28 '15 at 06:29
  • thanks, I tried in these way, ` #print x.executeScript("return arguments[0].childNodes[0].nodeValue;"); print driver.executeScript("return arguments[0].childNodes[0].nodeValue;",x)` none of them print any thing, need to explore more – nlper Jul 28 '15 at 06:59
  • @niper You cannot use x.executescript executescript executes JavaScript in the context of current window and acts on driver instance.you should pass the webelement as an argument like print driver_instance.executeScript("return arguments[0].childNodes[0].nodeValue;",x); – Vicky Jul 28 '15 at 08:29