简体   繁体   中英

Search facebook profiles With selenium headless browser

I'm trying to search facebook profiles using selenium and python via an headless chrome.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM