Reputation: 2397
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.
Upvotes: 0
Views: 781
Reputation: 3011
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
Upvotes: 1