seleniumfacebook-graph-apiweb-scrapingfacebook-comments

I am working with code but is does not provide me desire result. Can you please tell me how to Scrape Facebook comments text from fb live or post?


I want to scrape facebook comments from fb live or post,..is there any way to get this? If anyone know please help me.

I am using this but it does not working.

Code:

   comments = driver.find_elements_by_css_selector('.UFICommentBody span')
   print("Comment found " +str(len(comments)))
   for x in range(len(comments)): 
   print (comments[x]) 

Output:

  <selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="a0a4c59f-9c84-4a5c-855d-3ba51cea249a")>
  <selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="504c6ef2-e9fe-42b7-9f68-dcee5e7dbfde")>
  <selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="06d25f07-3a20-4783-98d7-f9c0ae01c230")>
  <selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="5e6b1e94-fee8-4636-9d9e-fd992c945c19")>

Solution

  • if you want to print text from your list then you can use for loop to retrieve each element through your list and then use .text with each object to print assoociated text.

    print("Comment found " +str(len(comments)))
       for x in range(len(comments)): 
       print (comments[x].text) 
    

    or

     print("Comment found " +str(len(comments)))
           for x in range(len(comments)): 
           print (x.text)