我正在处理一个需要我从网页中提取数据的项目。 为了开始,我使用以下代码来构建我的系统。注意 - 我使用的是PyCharm IDE和chrome。
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.snapdeal.com/product/skycandle-bfm-single-bucket-mop/684185386697#bcrumbSearch:skycandle')
html = driver.page_source
soup = BeautifulSoup(html)
print(soup.prettify())
Chrome的一个实例会打开,其中包含我在代码中提到的页面。但是' .prettify()'的预期输出。没有出现。 我收到以下错误 -
*
*
C:\Users\kp\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/kp/PycharmProjects/scrap_selenium/prog.py
Traceback (most recent call last):
File "C:/Users/kp/PycharmProjects/scrap_selenium/prog.py", line 28, in <module>
html = driver.page_source
File "C:\Users\kp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 500, in page_source
return self.execute(Command.GET_PAGE_SOURCE)['value']
File "C:\Users\kp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 237, in execute
self.error_handler.check_response(response)
File "C:\Users\kp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64)
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x0353C810>>
Traceback (most recent call last):
File "C:\Users\kp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 162, in __del__
File "C:\Users\kp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 138, in stop
File "C:\Users\kp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 109, in send_remote_shutdown_command
ImportError: sys.meta_path is None, Python is likely shutting down
Process finished with exit code 1
*
*
请纠正!