使用Selenium爬取动态网页
1.使用Selenium爬取动态网页
In [ ]:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.ptpress.com.cn/')
In [ ]:
driver.page_source
In [ ]:
driver.close()
In [ ]:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('http://www.ptpress.com.cn/shopping/index')
wait = WebDriverWait(driver, 10 ) # 等待10秒,如果搜索按钮没有出来就报错
confirm_btn = wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, '#header > div.container > div > div.col-md-8.tools > div.search > button')
))
# driver.close()
In [ ]:
driver.close()
2.参考文章
【创作不易,望点赞收藏,若有疑问,请留言,谢谢】