gpt4 book ai didi

java - 线程中的异常 "main"java.net.SocketTimeoutException : Read timed out in jsoup

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

我可以联系this link手动并使用 Firefox 浏览器正确搜索,但我无法使用 JSOUP 连接。

代码:

String url = "https://www.sosnc.gov/trademrk/search.aspx";
Connection.Response response = Jsoup.connect(url).timeout(45000)
.method(Connection.Method.GET)
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.3; rv:40.0) Gecko/20100101 Firefox/40.0")
.followRedirects(true)
.execute();
Map<String, String> loginCookies = response.cookies();
Document document = response.parse(); //search results
Element __VIEWSTATE = document.select("input[name=__VIEWSTATE]").first();
Element __VIEWSTATEGENERATOR = document.select("input[name=__VIEWSTATEGENERATOR]").first();
Element __PREVIOUSPAGE = document.select("input[name=__PREVIOUSPAGE]").first();
Element __EVENTVALIDATION = document.select("input[name=__EVENTVALIDATION]").first();
response = Jsoup.connect(url).timeout(45000)
.data("SosMenu_SiteTreeView_ExpandState", "ennnnnnnnnnnn")
.data("SosMenu_SiteTreeView_PopulateLog", "")
.data("SosMenu_SiteTreeView_SelectedNode", "SosMenu_SiteTreeViewn2")
.data("ToolsTreeView_ExpandState", "ennn")
.data("ToolsTreeView_PopulateLog", "")
.data("ToolsTreeView_SelectedNode", "")
.data("__EVENTARGUMENT", "")
.data("__EVENTTARGET", "")
.data("__EVENTVALIDATION", __EVENTVALIDATION.val())
.data("__PREVIOUSPAGE", __PREVIOUSPAGE.val())
.data("__VIEWSTATE", __VIEWSTATE.val())
.data("__VIEWSTATEGENERATOR", __VIEWSTATEGENERATOR.val())
.data("ctl00$ctl00$SosContent$SosContent$Submit1", "Search")
.data("ctl00$ctl00$SosContent$SosContent$Type", "Goods")
.data("ctl00$ctl00$SosContent$SosContent$txtSearc", query)
.cookies(loginCookies)
.method(Connection.Method.POST)
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.3; rv:40.0) Gecko/20100101 Firefox/40.0")
.header("host", "www.sosnc.gov")
.referrer("https://www.sosnc.gov/trademrk/search.aspx")
.followRedirects(true)
.execute();
document = response.parse(); //search results
System.out.println(document);

我错过了什么吗?是一个Jsoup post请求到服务器,所以我也添加了Cookie和所需的参数,但仍然无法得到结果。

最佳答案

我不知道为什么会超时,但您可以通过更简单的方式轻松获取数据 -

String query = "abc";
String url = "https://www.sosnc.gov/trademrk/results.aspx?searchstr=" +
query +
"&Type=GOODS";
Connection.Response response = Jsoup.connect(url).timeout(45000)
.method(Connection.Method.GET)
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.3; rv:40.0) Gecko/20100101 Firefox/40.0")

.followRedirects(true)
.execute();
System.out.println(response.body());

不需要 cookie 或额外参数。

关于java - 线程中的异常 "main"java.net.SocketTimeoutException : Read timed out in jsoup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39415320/

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