【发布时间】:2018-11-07 11:05:58
【问题描述】:
我正在尝试使用 python 使用 javascript 来报废页面。我是这方面的初学者,所以我阅读了很多教程。我终于发现我需要 selenium、beautiful_soup 和 firefox webdriver。所以我已经完成了一个功能(我也在添加相关模块)。
import bs4
import requests
from urllib.request import Request
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def page_souping_js(url):
options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=options)
driver.get(url)
complete_page = driver.page_source
driver.close()
page_soup = soup(complete_page,"html.parser")
return page_soup
在我尝试用它制作一个 .exe 文件(使用 pyinstaller)并在另一台出现此错误的计算机上运行它(它在我的计算机上运行良好)之前,它似乎工作正常:
selenium.common.exceptions.SessionNotCreatedException:消息:无法找到匹配的功能集
所以我再次阅读了该主题并“修复”了我的代码:
def page_souping_js(url):
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(capabilities=cap, firefox_options=options)
driver.get(url)
complete_page = driver.page_source
driver.close()
page_soup = soup(complete_page,"html.parser")
return page_soup
不过,由于我进行了更改,浏览器会打开,即使我添加了参数“--headless”也是如此。 1. 这两个,capabilities 和 firefox_options,不兼容吗? 2. 如果我需要将“marionette”设置为 False,有没有办法在不打开浏览器的情况下执行此功能?或者这个问题还有其他问题吗?
希望有人能回答这个问题。
【问题讨论】:
标签: python selenium pyinstaller