使用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.参考文章

【创作不易,望点赞收藏,若有疑问,请留言,谢谢】

posted @ 2022-07-01 15:32  东血  阅读(195)  评论(0编辑  收藏  举报

载入天数...载入时分秒...