簡體   English   中英

如何從 facebook 直播 stream 或帖子中抓取/獲取評論?

[英]How to scrape/get comments from facebook live stream or post?

我想從 fb live 或 post 中抓取 facebook 評論,..有什么辦法可以得到這個? 如果有人知道請幫助我。

我正在使用它,但它不起作用。

因為它沒有給出任何錯誤。 但是不檢索任何評論。

代碼:


import time
import re
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import sys
 
usr = ""
pwd = ""
 
url1 = "https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=100"
# url = sys.argv[1]
url = 'https://www.facebook.com/Typewritersvoice/photos/a.618454505026995/1619833381555764/'

# To block the notifications
options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
options.add_experimental_option("prefs",prefs)

driver = webdriver.Chrome(options=options,executable_path=r'C:\webdrivers\chromedriver')
    
# time.sleep(5)
driver.get(url1)
 
email = driver.find_element_by_xpath("//input[@id='email' or @name='email']")
email.send_keys(usr)
print("email entered...")
password = driver.find_element_by_xpath("//input[@id='pass']")
password.send_keys(pwd)
print("Password entered...")
button = driver.find_element_by_xpath("//button[@id='loginbutton']")
button.click()
print("button clicked...")

time.sleep(5)
print("login Successfully...")
driver.get(url)

print("Streaming URL entered...")

comments = driver.find_elements_by_css_selector('.UFICommentBody span')

print("Comment found " +str(len(comments)))

for x in range(len(comments)): 
    print (comments[x].text) 

OutPut:

email entered...
Password entered...
button clicked...
login Successfully...
Streaming URL entered...
Comment found 0

因為它沒有給出任何錯誤。 但是不檢索任何評論。

You better use xpath rather than css.selector, But in the new version of facebook its extremely hard to find the xpath, but still possible. 源代碼中沒有唯一 ID。

//div[@aria-posinset]//div[contains(@aria-label,'Comment by')]//a/span/span[@dir='auto']

例如,此 xpath 用於評論作者的 group-post-username。 不要忘記它僅適用於 facebook 的新版本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM