预期的浏览器二进制位置,但无法在默认位置找到二进制文件,无'moz:firefoxOptions.binary' (Python)



我正在尝试运行这个脚本

import crawler
crawler.crawl(url="https://www.montratec.com",output_dir="crawling_test",method="rendered-all")

从此库:https://github.com/SimFin/pdf-crawler

但我得到了这个错误:

Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

我已经安装了Firefox,并且正在使用Windows。

如果您将Firefox安装在系统搜索路径之外的非默认位置,您可以在moz:ffirefoxOptions功能对象上指定一个二进制字段(记录在README中(,或者在geckodriver启动时使用传递给它的--binary path标志。

由于Selenium被标记,您可以进行以下更改来消除上述错误:-

这是纯硒解决方案,如果您有一个正在运行的驱动程序实例,您可以使用FirefoxOptions重新配置它,如下所示:

options = webdriver.FirefoxOptions()
options.binary_location = r"C:Program FilesMozilla Firefoxfirefox.exe"
driver = webdriver.Firefox(executable_path=r'geckodriver.exe full path here', firefox_options=options)
driver.get("https://www.montratec.com1")

对于爬网程序(基于py3asyncio&aiohttp库的Web抓取框架。(

安装:

pip install crawler

示例代码:

import re
from itertools import islice
from crawler import Crawler, Request
RE_TITLE = re.compile(r'<title>([^<]+)</title>', re.S | re.I)
class TestCrawler(Crawler):
def task_generator(self):
for host in islice(open('var/domains.txt'), 100):
host = host.strip()
if host:
yield Request('http://%s/' % host, tag='page')
def handler_page(self, req, res):
print('Result of request to {}'.format(req.url))
try:
title = RE_TITLE.search(res.body).group(1)
except AttributeError:
title = 'N/A'
print('Title: {}'.format(title))
bot = TestCrawler(concurrency=10)
bot.run()

此处的官方参考

相关内容

最新更新