【发布时间】:2016-07-02 12:10:42
【问题描述】:
我尝试从这里解析 HTML 代码:https://opskins.com/?loc=shop_search&app=730_2&search_item=SSG+08+%7C+DARK+WATER+%28Field-Tested%29&sort=lh
但是站点 Opskins.com 有保护“机器人检测”,当您第一次访问站点时 - 您应该等待大约 5 秒钟,然后您将被重定向或重新加载到我需要的正确页面。
如何等待这 5 秒或此页面上的一些 HTML 代码?
Document doc = Jsoup.connect("https://opskins.com" + url)
.header("authority", "opskins.com")
.header("method", "GET")
.header("path", url)
.header("scheme", "https")
//до сюда с двоеточниями запросы
.header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
.header("accept-encoding", "gzip, deflate, sdch, br")
.header("accept-language", "ru,en-US;q=0.8,en;q=0.6")
.header("cache-control", "max-age=0")
//.header("cookie", "__cfduid=d76231c8cccdbd5303a7d4feeb3f3a11f1466541718; _gat=1; _ga=GA1.2.1292204706.1466541721; request_method=POST; _session_id=5dc49c7814d5087ac51f9d9da20b2680")
.cookie("steamLogin", "76561198065140894%7C%7C0C35CE73983BCA63E456B6A4831DD772D095AE77")
.cookie("steamLoginSecure", "76561198065140894%7C%7CCC21BEC8A5E8AD53E9C7086E51BDB8CE407C100A")
.cookie("steamMachineAuth76561198065140894", "8857F82DB9960F7B66F7842B5F880229A9AF63AB")
.header("dnt", "1")
.header("upgrade-insecure-requests", "1")
.userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36")
//.header("user-agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36")
.followRedirects(true)
.ignoreHttpErrors(true)
//.timeout(5000)
.get();
使用上面的代码,我可以获取页面 Bot 检测的 HTML 代码。
【问题讨论】:
-
当我使用 selenium 驱动程序时。我有下一个 JAVA 代码:
public boolean isWaitGood(By element) { try { WebDriverWait wait = new WebDriverWait(driver, 60); wait.until(ExpectedConditions.visibilityOfElementLocated(element)); return true; } catch(NoAlertPresentException ex) { return false; } }并执行它:if (isWaitGood(By.cssSelector("div.item-amount"))) { StringPrice = driver.findElement(By.cssSelector("div.item-amount")).getText(); }
标签: java parsing jsoup bots steam