# -*- coding: utf-8 -*-
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
"""运行chrome隐形窗口,不影响driver使用"""
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=options)
# """打开浏览器窗口"""
# driver=webdriver.Chrome()
url="https://m.jjwxc.net/book2/55648/1"
driver.get(url)
try:
element = (By.CLASS_NAME,"content_ul")
content_element = driver.find_element(*element)
content = content_element.text
save_path="/Users//story.txt"
with open(save_path,'w+') as page:
page.write(content)
except:
page_content=driver.page_source
print("页面未找到指定元素:",element,'\n\n',page_content)
driver.quit()
Python+Selenium 爬取页面内容
最新推荐文章于 2024-08-16 15:24:54 发布