简体   繁体   English

如何在jsoup中包装java.net.URL?

[英]how to wrap a java.net.URL in jsoup?

Jsoup.connect accept a string URL as parameter. Jsoup.connect接受字符串URL作为参数。 How let Jsoup connect accept a java.net.URL. 如何让Jsoup连接接受java.net.URL。

The use case is as following: The url (someurl/getimg) returns an img which is validation code, and it will also set the cookie. 用例如下:url(someurl / getimg)返回一个img,它是验证码,它还将设置cookie。 Since Jsoup can't read img, so I use java.net.URL and then openStream() to save the image, but I also want re-use the connection. 由于Jsoup无法读取img,因此我使用java.net.URL,然后使用openStream()保存图像,但我也想重新使用连接。 Since the cookie is set at session level, and I want to use jsoup to do automate web. 由于cookie是在会话级别设置的,因此我想使用jsoup来实现Web自动化。 If I just use 如果我只是用

 Jsoup.connect("someurl/login")

it will kick off a new connection, since it's a new connect, the session level cookie from the img will be expired. 它将启动一个新的连接,因为它是一个新的连接,所以来自img的会话级cookie将失效。

Basically I want to use java.net.URL to access the image from someurl/getimg, get the text from the image, and then fill the text in the image as validation code to login in. 基本上,我想使用java.net.URL从someurl / getimg访问图像,从图像中获取文本,然后将图像中的文本填充为验证码以登录。

You can use the following: 您可以使用以下内容:

Node node = wrap("someurl/login");

And that's it! 就是这样!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM