2017-07-27 54 views
-1

需要在点击一个显示我需要的表单的按钮后,用BeautifulSoup来取消网站的内容。我使用Selenium来点击按钮。 换句话说,在我做出一些改变其默认内容的操作后,我不知道如何取消网站。在对其进行一些更改之后刮去网站

我使用此代码点击按钮:

from bs4 import BeautifulSoup 
from selenium import webdriver 

site= "http://example.com" 

dr = webdriver.PhantomJS('./phantomjs') 
dr.get(site) 

loginButton = dr.find_element_by_xpath("//button[@ID='someId']") 
loginButton.click() 

回答

0

在进口部:

from bs4 import BeautifulSoup 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.support.select import Select 
from selenium.webdriver.support.ui import WebDriverWait 

你等到需要加载的一切,例如

WebDriverWait(dr, 30).until(
    EC.presence_of_all_elements_located((By.TAG_NAME, 'select')) 
) 

,然后您将网页驱动程序页面源添加到BeautifulSoup

source = BeautifulSoup(dr.page_source, "html.parser")