小编Tyl*_*ler的帖子

无法使用 python 中的 selenium 4 的 option.set_preference 加载现有的 firefox 配置文件

我有这段代码可以工作并加载 Firefox 配置文件

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile


ffOptions = Options()
ffProfile = FirefoxProfile(r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
ffOptions.profile = ffProfile

driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)

仅它给出以下弃用警告:

firefox_profile 已被弃用,请使用 Options 对象

设置配置文件已被弃用。请使用 set_preference 和 install_addons 方法

为了解决警告,我尝试将代码更新为

from selenium import webdriver
from selenium.webdriver.firefox.options import Options


ffOptions = Options()
ffOptions.set_preference('profile', r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
    
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)

现在没有警告,但浏览器打开时未设置配置文件,它是一个空白配置文件。

selenium python-3.x selenium-firefoxdriver firefox-profile selenium4

10
推荐指数
1
解决办法
6569
查看次数

从Bash管道输入到C++ cin

我正在尝试编写一个简单的Bash脚本来编译我的C++代码,在这种情况下,它是一个非常简单的程序,它只是将输入读入一个向量,然后打印向量的内容.

C++代码:

    #include <string>
    #include <iostream>
    #include <vector>

    using namespace std;

    int main()
    {
         vector<string> v;
         string s;

        while (cin >> s)
        v.push_back(s);

        for (int i = 0; i != v.size(); ++i)
        cout << v[i] << endl;
    }
Run Code Online (Sandbox Code Playgroud)

Bash脚本run.sh:

    #! /bin/bash

    g++ main.cpp > output.txt
Run Code Online (Sandbox Code Playgroud)

因此,编译我的C++代码并创建a.out和output.txt(由于没有输入,它是空的).我尝试了一些使用"input.txt <"的变种而没有运气.我不知道如何将我的输入文件(只是几个随机单词的简短列表)传递给我的c ++程序.

c++ bash input pipe cin

5
推荐指数
2
解决办法
1万
查看次数

如何使用鼠标拖动事件在Java小程序上绘制一个矩形并使其保持不变

我的程序可以绘制矩形.我有两个问题我无法解决.绘制矩形后,它不会停留.我有唯一的代码清除画布下的画布,重绘仅在鼠标拖动时调用.为什么当鼠标释放或鼠标移动时我的画布清晰.第二件事不是问题,而是我无法弄清楚的事情,当我的矩形的高度或宽度为负时,矩形填充为黑色.

package pracpapp2;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MouseTracker4July extends JFrame
   implements MouseListener, MouseMotionListener {


  private static final long serialVersionUID = 1L;
  private JLabel mousePosition;
  int x, y;
  int x1, x2, y1, y2;
  int w, h;
  private JLabel recStart;
  private JLabel recStop;
  private JLabel cords;
   // set up GUI and register mouse event handlers
   public MouseTracker4July()
   {
      super( "Rectangle Drawer" );

      mousePosition = new JLabel();
      mousePosition.setHorizontalAlignment(SwingConstants.CENTER);
      getContentPane().add( mousePosition, BorderLayout.CENTER );


      JLabel text1 = new JLabel();
      text1.setText( "At …
Run Code Online (Sandbox Code Playgroud)

java swing drawing mouseevent

3
推荐指数
1
解决办法
2万
查看次数

尝试使用Java中的Catch Block

所以我给了这个代码,我必须创建一个Exception,然后用一个Try/CatchBlock来捕获它.我已经在代码的底部制作了Exception.但我以前从未使用过Try/CatchBlock,也不确定如何实现它.

例外情况enum是输入未列在其下的排名.我也需要使用toString带有被捕获的异常,但我很确定我可以找出那个.

package pracapp4;

import java.util.Scanner;

public class Staff extends Employee
{

  enum Title
  {
    DEPARTMENT_HEAD, DIRECTOR, DEAN, VICE_CHANCELLOR, CHANCELLOR
  }

  private Title title;

  public Staff()
  {
    super();
    title = Title.DEPARTMENT_HEAD;
  }

  public Staff(String firstName, String lastName, int salary, Title title)
  {
    super(firstName, lastName, salary);
    this.title = title;

  }

  @Override
  public String toString()
  {
    return super.toString() + "\n\tTitle: " + title;
  }


  @Override
  public void display()
  {

    System.out.println("<<Staff>>" + this);

  }

  @Override …
Run Code Online (Sandbox Code Playgroud)

java exception try-catch

2
推荐指数
1
解决办法
2956
查看次数

使用 Go 自定义 404 错误消息

我有这个代码,如果我去 /time/ 会给出我的自定义 404 错误消息,但如果我去 /times/ 或只是 / 或 /whatever 然后我会得到默认的 404 错误消息。我想为除 /time/ 以外的所有情况显示我的自定义 404

package main

import (
        "fmt"
        "time"
        "flag"
        "os"
        "net/http"
        )

const AppVersion = "timeserver version: 3.0"

func timeserver(w http.ResponseWriter, r *http.Request) {
    if r.URL.Path != "/time/" {
        NotFoundHandler(w, r)
        return
    }

    const layout = "3:04:05 PM"
    t := time.Now().Local()
    fmt.Fprint(w, "<html>\n")
    fmt.Fprint(w, "<head>\n")
    fmt.Fprint(w, "<style>\n")
    fmt.Fprint(w, "p {font-size: xx-large}\n")
    fmt.Fprint(w, "span.time {color: red}\n")
    fmt.Fprint(w, "</style>\n")
    fmt.Fprint(w, "</head>\n")
    fmt.Fprint(w, "<body>\n")
    //fmt.Fprint(w, "The time is now …
Run Code Online (Sandbox Code Playgroud)

http go http-status-code-404

1
推荐指数
1
解决办法
1703
查看次数

了解C++字符串连接

在C++中,我试图理解为什么在构造这样的字符串时不会出现错误:

const string hello = "Hello";
const string message = hello + ", world" + "!";
Run Code Online (Sandbox Code Playgroud)

但你得到一个编译时错误:

const string exclam = "!";
const string msg =  "Hello" + ", world" + exclam
Run Code Online (Sandbox Code Playgroud)

编译时错误是:

main.cpp:10:33: error: invalid operands of types ‘const char [6]’ and 
‘const char [8]’ to binary ‘operator+’
Run Code Online (Sandbox Code Playgroud)

为什么第一次运行正常但第二次生成编译时错误?

c++ string concatenation string-concatenation

0
推荐指数
1
解决办法
171
查看次数