[英]Search facebook profiles With selenium headless browser
I'm trying to search facebook profiles using selenium and python via an headless chrome. 我正在尝试通过无头的chrome使用硒和python搜索facebook个人资料。
I successfully get to my logged in page but when i enter text into the searchbar i get no results back. 我成功进入登录页面,但是当我在搜索栏中输入文字时,我没有任何结果。
#!/usr/bin/env python
import os
import sys
import wget
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from pyvirtualdisplay import Display
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
display = Display(visible=0, size=(800, 800))
display.start()
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://facebook.com") # load the web page
email = driver.find_element_by_xpath("//input[@name='email']")
password = driver.find_element_by_xpath("//input[@name='pass']")
btn = driver.find_element_by_xpath("//input[@value='Logga in']")
email.send_keys("email@email.com")
password.send_keys("password")
btn.click()
searchbox = driver.find_element_by_xpath("//form[@action='/search/web/direct_search.php']//input")
searchbox.send_keys("name")
src = driver.page_source
print src.encode('utf-8')
driver.close()
Any ideas? 有任何想法吗?
我通过在btn.click()之后放置另一个请求来解决它
driver.get("https://www.facebook.com/search/top/?q=name")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.