gpt4 book ai didi

java - HTMLUnit:获取没有名称、id 的按钮,仅键入 onclick=

转载 作者:行者123 更新时间:2023-11-30 07:05:08 25 4
gpt4 key购买 nike

如何在没有名称、ID 或类似类型的情况下获得按钮按钮?

这是我尝试管理的 HTML 代码:

<a class="btnv6_blue_hoverfade btn_small" href="#"   
onclick="DoAgeGateSubmit(); return false;">
<span>Fortfahren</span>
</a>

这是我现在的代码:

package htmlParser;

import java.io.IOException;
import java.net.URL;
import org.jsoup.nodes.Element;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.RefreshHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlImage;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class HitTheDamnButton
{

public static void main(String[] args) throws Exception
{
String url = "http://store.steampowered.com/agecheck/app/72850/? snr=1_7_7_230_150_2";
WebClient webClient = new WebClient();
HtmlPage startPage = webClient.getPage(url);
HtmlForm form = (HtmlForm) startPage.getElementById("agecheck_form");
HtmlSelect dropDown1 = form.getSelectByName("ageDay");
HtmlSelect dropDown2 = form.getSelectByName("ageMonth");
HtmlSelect dropDown3 = form.getSelectByName("ageYear");
dropDown1.setSelectedAttribute("2", true);
dropDown2.setSelectedAttribute("February", true);
dropDown3.setSelectedAttribute("1970", true);
webClient.close();
}
}

我怎样才能点击这个按钮?我尝试了一切

HTMLButton button =  form.getButtonByName("a.btnv6_blue_hoverfade.btn_small");
... form.hasAttribute(), ... getSelectByName("name");

但是没有任何效果。

感谢您提前提供的任何帮助!

最佳答案

您正在寻找的是 anchor 而不是按钮。尝试诸如 startPage.getAnchorByText 或 startPage.getAnchors 之类的方法,然后迭代并比较类和/或文本以获得正确的类和/或文本。

关于java - HTMLUnit:获取没有名称、id 的按钮,仅键入 onclick=,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40268482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com