- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以联系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/
我有一个给定的 FTP 服务器。我可以通过 WinSCP 和其他程序连接到服务器。我已经通过 Java 连接到服务器,但过了一会儿我无法连接。根据 WinSCP,我可以一直连接。现在的问题是服务器是问
以下代码应根据是否达到超时抛出异常: public boolean isAlive(int workerNum) throws Exception { System.out.println("
我正在编写一个从服务器接收数据的 Android 应用程序。理论上不可能有互联网连接,所以我尝试通过捕获 SocketTimeoutException 来显示错误消息重试屏幕或其他内容来捕获这种情况。
我试图在我的 Android 手机上测试我的第一个应用程序,但扫描后,我收到以下错误消息: “ Uncaught Error :java.error.sockettimeoutexception:10
当客户端 A 连接到服务器 B 时,我们在服务器 B 上收到 java.net.SocketTimeoutException。不知道为什么。客户端正在向服务器发送数据,然后服务器抛出此异常。如何解决此
以下是我尝试编写的 Java 应用程序的一小部分: Socket socket = new Socket(hostname, portnumber); DataInputStream socketIn
'java.net.SocketTimeoutException:连接超时' 循环一段时间后我收到此错误。为什么我会收到 SocketTimeoutException?我该如何修复这个错误? @Ove
很抱歉,如果这已发布在我工作/寻找几天的地方。 问题: 当通过对等网络与 Android 设备进行通信时,我收到 SocketTimeoutExceptions。 详细信息: 发生这种情况时,andr
我正在尝试使用 DOT NET 网络服务将我的 Android 应用程序连接到我计算机中存在的 MySql 数据库(本地主机)。我能够仅通过单一输入 (EditText) 连接到在线数据库。这里有 3
我正在我的 android 应用程序中使用改造构建一个 Restful 客户端,但是我在尝试从我的网络服务中检索数据时遇到异常,第一次调用毫无异常(exception)地工作,但我更改了参数并重试获取
我有一个复杂的应用程序,可以从我在 AWS 上的网络服务下载大量内容。但是,我一直有 50% 的时间收到 SocketTimeoutException。根据我的研究,我怀疑可能有以下原因: 连接超时
我想在我的应用程序中使用 REST API。它为我从这个应用程序发出的所有请求抛出 SocketTimeoutException。 Logcat 输出:(您也可以在此处看到带有漂亮格式的输出:http
假设我有一个名为 SuperSocket 的套接字变量,有什么方法可以捕获超时异常吗? SuperSocket.setSoTimeout(5000); catch (Soc
我为 Retrofit 设置: private Interceptor interceptor = new Interceptor() { @Override publ
我正在尝试向服务器发送 POST 请求以获取数据,但有时会发生 SocketTimeoutException! 我使用 Ok3Client 解决了它,但我遇到了同样的异常我该如何解决它? 我的代码在下
我正在运行多个工作线程(大约 10 个)来访问来自 redis Q 的数据。 对于我正在为 Jedis Client 使用无限超时。 Jedis jedis = pool.getResource();
我有一个运行spring-boot的应用程序,可以访问mongodb 当我使用单个docker run命令时,该应用程序运行正常。但是,当我尝试将它们全部作为服务运行时,由于某种原因,该应用程序永远无
我正在开发一个 Web 应用程序,它接受来自第三方的 json 数据,处理该数据并使用处理后的 json 数据响应它们。 我在生产服务器上收到 java.net.SocketTimeoutExcept
我们正在学习使用 JSOUP 和 urlconnection,因此我们正在解析我们选择的网站中的页面,并解析页面以回答有趣的问题。 一切正常,但是时不时地我会收到 SocketTimeOutExcep
我正在编写一个小应用程序,它使用深度优先搜索通过URL扫描所有页面。所以我应该多联系。在 n 页之后,我通常会捕获 SocketTimeoutException 并且我的应用程序崩溃。那么避免这种情况
我是一名优秀的程序员,十分优秀!