提问人:Михаил А 提问时间:9/11/2023 更新时间:9/11/2023 访问量:25
使用 csrf 解析站点
Parsing site with csrf
问:
您能否就如何处理解析 dns-shop 网站 (https://www.dns-shop.ru/) 提供建议?我需要使用 Jsoup 从页面中检索一些数据。据说dns-shop对CSRF有很好的保护。
private String url = "https://www.dns-shop.ru/";
@Scheduled(fixedDelay = 5000)
public Document connectAndGet() throws IOException {
return Jsoup.connect(url)
.userAgent("Mozilla")
.timeout(10000)
.referrer("https://google.com")
.get();
}
当我尝试运行代码时,我收到 401 Unauthorized 错误。我还应该提到,我在使用 eBay 和亚马逊等资源时不会遇到这样的问题,那里的一切都正确连接。我怀疑问题可能与 cookie 甚至令牌有关。我需要访问该页面并从中提取数据。
此代码的错误是:
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=401, URL=[https://www.dns-shop.ru/]
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:912) ~[jsoup-1.16.1.jar:1.16.1]
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:851) ~[jsoup-1.16.1.jar:1.16.1]
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:345) ~[jsoup-1.16.1.jar:1.16.1]
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:330) ~[jsoup-1.16.1.jar:1.16.1]
at com.xxx.connectAndGet(ParseSite.java:31) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-6.0.11.jar:6.0.11]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
答: 暂无答案
评论