应为浏览器二进制位置,但在默认位置找不到二进制,没有“moz:firefoxOptions.binary”(Python)

2024-10-02 18:24:24 发布

您现在位置: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


Tags: nohttpsimport脚本comurloutputwww
2条回答

如果您将Firefox安装在系统搜索路径之外的非默认位置,则可以在moz:firefoxOptions功能对象(在自述文件中记录)上指定二进制字段,或者在启动时使用传递给geckodriver的二进制路径标志

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

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

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

用于爬虫程序(基于py3 asyncio和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()

正式参考here

相关问题 更多 >