Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual C#-Web浏览器检查页面上的文本,如果发现文本,请执行某些操作_C#_Visual Studio_Webbrowser Control - Fatal编程技术网

Visual C#-Web浏览器检查页面上的文本,如果发现文本,请执行某些操作

Visual C#-Web浏览器检查页面上的文本,如果发现文本,请执行某些操作,c#,visual-studio,webbrowser-control,C#,Visual Studio,Webbrowser Control,我的表格上有网络浏览器。下面是html: <div class="life">Health:<span id="currenthp">4473</span>/<span id="maxhp">4473</span><div class="bar"> 健康:4473/4473 因此,我想做一个if-else检查——例如,如果要做某事,当前HP为2000或更少。如果当前HP小于等于2000,我如何使用计时器每3分钟检查

我的表格上有网络浏览器。下面是html:

<div class="life">Health:<span id="currenthp">4473</span>/<span id="maxhp">4473</span><div class="bar">
健康:4473/4473


因此,我想做一个if-else检查——例如,如果要做某事,当前HP为2000或更少。如果当前HP小于等于2000,我如何使用计时器每3分钟检查一次?既然你问了两件事,我将分两部分回答:

查找当前HP的值:

public int findValue(String html) {
    // html being the HTML code currently in your browser
    int start = html.IndexOf("currenthp"); // find occurrence of 'currenthp' 
    start += "currenthp\">".Length; // update location to right after that id
    String newStr = arg.Substring(start); // take the substring from there
    int end = newStr.IndexOf("<"); // find the first occurrence of '<' (right after currenthp's value)
    int val = Int32.Parse(newStr.Substring(0, end)); // Extract the value
    return val;
}

现在您只需使用自己的函数填写
refreshCurrentHp
,就可以了。

既然您问了两件事,我将分两部分回答:

查找当前HP的值:

public int findValue(String html) {
    // html being the HTML code currently in your browser
    int start = html.IndexOf("currenthp"); // find occurrence of 'currenthp' 
    start += "currenthp\">".Length; // update location to right after that id
    String newStr = arg.Substring(start); // take the substring from there
    int end = newStr.IndexOf("<"); // find the first occurrence of '<' (right after currenthp's value)
    int val = Int32.Parse(newStr.Substring(0, end)); // Extract the value
    return val;
}

现在,您只需使用自己的函数填写
refreshCurrentHp
,就可以了。

到目前为止您尝试过什么吗?这个问题并没有显示太多细节。此外,这很可能需要一些JQuery来检查html中的值,以及一个使用System.Threading.timer()的自定义计时器。到目前为止,您尝试过什么吗?这个问题并没有显示太多细节。此外,这很可能需要一些JQuery来检查html中的值,以及使用System.Threading.timer()的自定义计时器。错误2当前上下文中不存在名称“arg”。我在findValue函数中遇到此错误。。。此外,我将使用此函数查找值,但如何检查值是否为2000或更低?无论如何,谢谢你的快速回复!:)这件事是我的错。应替换为
html
。函数
findValue
返回当前HP的值。因此,现在您只需要创建另一个函数来检查它是否高于2000。错误2当前上下文中不存在名称“arg”。我在findValue函数中遇到此错误。。。此外,我将使用此函数查找值,但如何检查值是否为2000或更低?无论如何,谢谢你的快速回复!:)这件事是我的错。应替换为
html
。函数
findValue
返回当前HP的值。所以现在你只需要做另一个函数来检查它是否高于2000。