{"id":738,"date":"2022-11-21T10:03:44","date_gmt":"2022-11-21T02:03:44","guid":{"rendered":"https:\/\/www.vmlogin.com.cn\/help\/?p=738"},"modified":"2023-05-18T15:52:49","modified_gmt":"2023-05-18T07:52:49","slug":"api%e5%90%af%e5%8a%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e4%bb%a3%e7%a0%81%ef%bc%88java%e7%89%88","status":"publish","type":"post","link":"https:\/\/www.vmlogin.com.cn\/help\/api\/java-code.html","title":{"rendered":"API\u542f\u52a8\u6d4f\u89c8\u5668\u4ee3\u7801\uff08JAVA\u7248)"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package com.ruoyi.threed;\r\n\r\n\r\nimport com.alibaba.fastjson2.JSONObject;\r\nimport org.openqa.selenium.remote.DesiredCapabilities;\r\nimport org.openqa.selenium.remote.RemoteWebDriver;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.openqa.selenium.chrome.ChromeOptions;\r\n\r\nimport java.io.BufferedReader;\r\nimport java.io.InputStreamReader;\r\nimport java.net.HttpURLConnection;\r\nimport java.net.URL;\r\nimport java.util.Map;\r\n\r\npublic class BrowserProfile {\r\n    public static void main(String&#91;] args) throws Exception {\r\n        BrowserProfile bp = new BrowserProfile();\r\n\r\n        String profileId = \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\";\r\n\r\n        String ss = bp.startProfile(profileId);\r\n        System.out.println(\"ss:\"+ss);\r\n\r\n\r\n        Map&lt;String,Object> _map =  JSONObject.parseObject( ss.toString(),Map.class);\r\n        String vaa = _map.get(\"value\").toString();\r\n        System.out.println(\"value()\"+vaa.toString());\r\n        URL url = new URL(vaa);\r\n        String  dizip =url.getAuthority().replace(\"http:\/\/\",\"\");\r\n        System.out.println(\"dizip:\"+dizip);\r\n\r\n        String drvstr = _map.get(\"chromedriver\").toString();\r\n\r\n        System.setProperty(\"webdriver.chrome.driver\",drvstr);\r\n       \r\n        ChromeOptions options = new ChromeOptions();\r\n        options.setExperimentalOption(\"debuggerAddress\",dizip);\r\n        WebDriver driver = new ChromeDriver(options);\r\n  \r\n\r\n        \/\/\u8bbf\u95eevmlogin\r\n        driver.navigate().to(\"http:\/\/www.vmlogin.com.cn\");\r\n        System.out.println(driver.getTitle());\r\n        driver.quit();\r\n    }\r\n\r\n    private String startProfile(String profileId) throws Exception {\r\n\r\n  \r\n        String url = \"http:\/\/127.0.0.1:35000\/api\/v1\/profile\/start?skiplock=true&amp;profileId=\" + profileId;\r\n     \r\n        URL obj = new URL(url);\r\n        HttpURLConnection con = (HttpURLConnection) obj.openConnection();\r\n\r\n        con.setRequestMethod(\"GET\");\r\n\r\n        BufferedReader in = new BufferedReader(\r\n                new InputStreamReader(con.getInputStream()));\r\n        String inputLine;\r\n        StringBuffer response = new StringBuffer();\r\n\r\n        while ((inputLine = in.readLine()) != null) {\r\n            response.append(inputLine);\r\n        }\r\n        in.close();\r\n        System.out.println(\"response.toString()\"+response.toString());\r\n    \r\n        Thread.sleep(3000);\r\n        return response.toString();\r\n    }\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-738","post","type-post","status-publish","format-standard","hentry","category-api"],"_links":{"self":[{"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/posts\/738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/comments?post=738"}],"version-history":[{"count":3,"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/posts\/738\/revisions"}],"predecessor-version":[{"id":3024,"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/posts\/738\/revisions\/3024"}],"wp:attachment":[{"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/media?parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/categories?post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vmlogin.com.cn\/help\/wp-json\/wp\/v2\/tags?post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}