如何将价值从网站转移到在线 windows 表格?

How to transfer value from website to windows forms online?

我正在 Windows 窗体上创建应用程序并遇到了麻烦。 我每秒通过 Selenium Webdriver 从网站获取一个值,使用 XPath 并将其记录到我的本地字符串中。我正在获得计时器的价值。没关系,像串一样弄到手对我来说很舒服

所以。我有一个循环,它从网站读取数据,我每秒也把这个字符串放到 TextBox 中。

但是在我的循环 运行 之前我无法看到文本框的输出。我不想阻止它。

我想在我的应用程序中查看在线网站的值。 你知道如何每秒刷新表单吗? 如果你需要,我可以提供我的代码。

提前谢谢您,我的导师!

   public static ChromeDriver GetDriver() {
       return new ChromeDriver();
      }

      public static void CheckGame(string URLevent) {
       while (GameIsRun) {
        GetInformation(GetDriver(), URLevent);
        GameIsRun = false;
       }
      }

      static void GetInformation(ChromeDriver driver, string URLevent) {
       driver.Navigate().GoToUrl(URLevent);
       do {
        TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/" + 
           "div[@class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");
        Print print = new Print()
        print.Info(TimeOfGame);
        System.Threading.Thread.Sleep(1000);
       }
       while (TimeOfGame != "90:00");
      }

      public partial class Form1: Form {
       public Form1() {
        InitializeComponent();
       }

       private void Form1_Load(object sender, EventArgs e) {
        Form form = new Form();
       }

       private static Form1 _form = null;
       public static Form1 Form {
        get {
         if (_form == null) {
          _form = new Form1();
         }
         return _form;
        }
       }

       private void button1_Click(object sender, EventArgs e) {
        string eventId = tbEventID.Text; //this works vice versa. It's not my issue.
        string URLevent = "url..." + tbEventID.Text + "/";
        Program.CheckGame(URLevent);
       }
      }

      public class Print {
       public void Info(string TimeOfGame) {
        Form1.Form.tbTeam1.Text = TimeOfGame; 
        //my issue is here. I want to check result at TextBox each second! 
       }
      }

您代码中的这条语句

TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/div[@class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");

非常脆弱。您应该使用 getText() 方法来提取 HTML 方法的内部文本。此外,为了精确定位 webElement,最好使用相对 Xpath 而非绝对 Xpath。