我想运行firefox无头.
不隐藏浏览器窗口或在虚拟桌面中打开它,Firefox通过使用"-headless"标志支持无头模式.
问题是我知道如何在Chrome中执行此操作但不在Firefox中.
我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace MyApp {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
private void StartBtn_Click(object sender, EventArgs e) {
IWebDriver driver;
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--headless");
driver = new FirefoxDriver(options);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的WinForm应用程序只有一个名为StartBtn的按钮.单击按钮时,Firefox应无头运行,但会在正常窗口中打开.
更新 我将firefox更新为56.0.1
现在我得到一个不同的错误:
WebDriver.dll中发生未处理的"OpenQA.Selenium.WebDriverException"类型异常
附加信息:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,未提供'moz:firefoxOptions.binary'功能,并且在命令行上未设置二进制标志
我需要使用C#在Selenium中使用现有的Firefox配置文件.该配置文件具有我需要的已配置插件.
我发现了一些代码谷歌搜索,但那些是Java,我尝试了以下代码,但它仍然无法正常工作.
FirefoxProfile profile = new FirefoxProfile("C:\\Users\\username\\Desktop\\software\\Files");
driver = new FirefoxDriver();
Run Code Online (Sandbox Code Playgroud) 我需要在视频中添加两个文本。第一个文本在前 6 秒内显示在右下角,第二个文本在最后 3 秒内显示在视频中央。
下面是我的代码:
ffmpeg -i input.mp4 -vf drawtext="text='Stack Overflow': fontcolor=white: borderw=2: fontfile=Arial Black: fontsize=w*0.04: x=(w-text_w)-(w*0.04): y=(h-text_h)-(w*0.04): enable='between(t,0,6)'", -vf drawtext="text='Stack Overflow': fontcolor=white: borderw=2: fontfile=Arial Black: fontsize=w*0.04: x=(w-text_w)/2: y=(h-text_h)/2: enable='between(t,7,10)'" -codec:a copy output2.mp4
Run Code Online (Sandbox Code Playgroud)
运行上面的代码没有出现任何错误,但在输出文件中,仅应用了第二个绘制文本。
我正在制作 django 应用程序,无法在views.py 文件中导入自定义模块。
我正在尝试从 Integrations/views.py 的模块文件夹内的 auth.py 导入类“Integrate”
我尝试放入__init.py__应用程序文件夹和模块文件夹内,但仍然不起作用。
视图.py:
from ..modules.auth import Integrate
Run Code Online (Sandbox Code Playgroud)
电源外壳:
from ..modules.auth import Integrate
ValueError: Attempted relative import beyond toplevel package
Run Code Online (Sandbox Code Playgroud) 我正在使用 scrapy 来抓取阿迪达斯网站:http://www.adidas.com/us/men-shoes。但它总是显示错误:
用户超时导致连接失败:获取http://www.adidas.com/us/men-shoes花费的时间超过 180.0 秒..
它重试了 5 次,然后完全失败。
我可以访问 chrome 上的 url,但它在scrapy 上不起作用。
我试过使用自定义用户代理并模拟标头请求,但它仍然不起作用。
下面是我的代码:
import scrapy
class AdidasSpider(scrapy.Spider):
name = "adidas"
def start_requests(self):
urls = ['http://www.adidas.com/us/men-shoes']
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Host": "www.adidas.com",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
}
for url in urls:
yield scrapy.Request(url, self.parse, headers=headers)
def parse(self, response):
yield(response.body)
Run Code Online (Sandbox Code Playgroud)
爬虫日志:
{'downloader/exception_count': 1,
'downloader/exception_type_count/twisted.web._newclient.ResponseNeverReceived': …Run Code Online (Sandbox Code Playgroud) 我有以下日期/时间格式的字符串:
2018-05-20T07:06:23.226
我需要将其转换为以下格式:
2018-05-20 06:23上午
我尝试了以下代码,但是我肯定在这里犯了一些错误:
date = "2018-05-20T07:06:23.226"
d = datetime.datetime.strptime('date', '%Y-%m-%dT%H:%M:%S.%f')
new_date = d.strftime('%y-%m-%d %H:%M %p')
Run Code Online (Sandbox Code Playgroud)
我总是收到以下错误:
ValueError:时间数据“日期”与格式“%Y-%m-%dT%H:%M:%S.%f”不匹配