[英]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.