Skip to content Skip to sidebar Skip to footer

Facebook Selenium How Can I Get The Number Of Likes

I am trying to get the numbers of people who liked the post with the below code. I tried both methods both are not working. It does return error code. Could someone assist, appreci

Solution 1:

Also tried to escape in different ways, but same result - Seems that xpath has a problem with the " from the html and means that they were closed, so

driver.find_element_by_xpath('//span[@id="u_0_r"]').get_attribute('data-store')

only detects the opening {

Id of parent div is generated automatically and position of icons in it is ordered by count of clicks.

You could use the class of the i tag until there is a better solution, that really would interest me:

from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Program Files\ChromeDriver\chromedriver.exe')

html_content = '''
<divclass="scrollAreaColumn"><spanname="one"data-store="{"reactionType":1}"><span>133</span></span><spanname="two"data-store="{"reactionType":1}"><iclass="_2ep2 img sp_FnpQQMXWL5W sx_4760b1"></i><span>128</span></span><spanname="three"data-store="{"reactionType":1}"><iclass="_2ep2 img sp_FnpQQMXWL5W sx_4760b1 xyz"></i><span>128</span></span></div>       
'''
driver.get("data:text/html;charset=utf-8,{html_content}".format(html_content=html_content))
count = driver.find_element_by_xpath('//i[@class="_2ep2 img sp_FnpQQMXWL5W sx_4760b1"]/following-sibling::span').text
print(count)

driver.close()

Solution 2:

You can try this xpath:

'//span[@data-store=\"{\'reactionType\':1}\"]//span[@data-sigil="reaction_profile_tab_count"]'

Post a Comment for "Facebook Selenium How Can I Get The Number Of Likes"