scrapy中使用Selector获取selenium响应页面

from selenium import webdriver
from scrapy import Selector
def set_driver(self):
        """
        设置webdriver
        """
        chrome = webdriver.ChromeOptions()
        chrome.headless = True  # 设置无头浏览器
        path = r'chromedriver/chromedriver.exe'
        driver = webdriver.Chrome(options=chrome, executable_path=path)
        return driver
driver = self.set_driver()
driver.get(url)
# 获取webdriver响应页面
selenium_response = Selector(text=driver.page_source, type='html')

不仅仅是可以用于selenium,requests也可以,如下:

r = requests.get(url=url, headers=headers, timeout=(30, 60))
# 获取响应
response = Selector(text=r.text, type='html')

你可能感兴趣的:(scrapy中使用Selector获取selenium响应页面)