Ver Fonte

哦哦哦

lwhhszx há 2 anos atrás
commit
0a4773e8a6

+ 13 - 0
src/main/java/com/example/demo/DemoApplication.java

@@ -0,0 +1,13 @@
+package com.example.demo;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class DemoApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(DemoApplication.class, args);
+    }
+
+}

+ 54 - 0
src/main/java/com/example/demo/base/Constants.java

@@ -0,0 +1,54 @@
+package com.example.demo.base;
+
+public class Constants {
+    public static final String REPORT_API = "/api/report/api";
+
+    public static final String NET_ERROR = "网络异常";
+
+    /**
+     * 分隔符-竖线
+     */
+    public static final String SEPARATOR_VERTICAL_BAR = " | ";
+
+    /**
+     * 专利类型
+     */
+    public static final String PATENT_TYPE = "PATENT_TYPE";
+
+    public static final Integer TASK_IMPORT_PATENT = 1;
+    /**
+     * 机构类型
+     */
+    public static final String ORGAN_TYPE = "ORGAN_TYPE";
+
+    /**
+     * 许可人/被许可人
+     */
+    public static final String LICENSOR_TYPE = "LICENSOR_TYPE";
+
+    /**
+     * 简单法律状态
+     */
+    public static final String PATENT_SIMPLE_STATUS = "PATENT_SIMPLE_STATUS";
+
+    /**
+     * 国家
+     */
+    public static final String COUNTRIES = "COUNTRIES";
+
+    /**
+     * 法律状态
+     */
+    public static final String PATENT_STATUS = "PATENT_STATUS";
+
+    /**
+     * 企业应用场景
+     */
+    public static final String ENTERPRISE_APPLICATION_SCENARIO = "ENTERPRISE_APPLICATION_SCENARIO";
+
+    /**
+     * 调查类型
+     */
+    public static final String INVESTIGATION_TYPE = "INVESTIGATION_TYPE";
+
+}

+ 104 - 0
src/main/java/com/example/demo/controller/AssoTaskPersonelController.java

@@ -0,0 +1,104 @@
+package com.example.demo.controller;
+
+import com.example.demo.base.Constants;
+import com.example.demo.domain.PatentCell;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@Tag(name = "任务人员操作")
+@RestController
+@RequestMapping(Constants.REPORT_API + "/AssoTaskPersonel")
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class AssoTaskPersonelController {
+    @GetMapping("/getPartClient")
+    @Operation(summary = "分页获取对比专利")
+    public List<PatentCell> getPagination(String patentVO) throws IOException, InterruptedException {
+        System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
+        // 1.创建webdriver驱动
+        WebDriver driver = new ChromeDriver();
+        // 2.打开百度首页
+        driver.get("https://account.zhihuiya.com");
+        TimeUnit.MILLISECONDS.sleep(1000);//毫秒
+        // 3.获取“百度一下”按钮,进行搜索
+        driver.findElement(By.id("tab-password")).click();
+        // 3.获取输入框,输入selenium
+        List<WebElement> ret = driver.findElements(By.className("el-input__inner"));
+        ret.get(0).sendKeys("huangyu@china-wispro.com");
+        ret.get(1).sendKeys("wispro#IP257");
+
+        driver.findElement(By.className("el-button")).click();
+        TimeUnit.MILLISECONDS.sleep(2000) ;//毫秒
+       List<WebElement> alerts= driver.findElements(By.className("patsnap-el-confirm"));
+       if(alerts.size()!=0){
+
+           alerts.get(0).click();
+       }
+        TimeUnit.MILLISECONDS.sleep(8000);//毫秒
+        List<WebElement> ret1= driver.findElements(By.className("div-textarea"));
+        ret1.get(0).sendKeys(patentVO);
+        TimeUnit.MILLISECONDS.sleep(1000);//毫秒
+        WebElement rr=  driver.findElement(By.className("search-form__btn"));
+        TimeUnit.MILLISECONDS.sleep(1000);//毫秒
+        rr.click();
+
+        TimeUnit.MILLISECONDS.sleep(5000);//毫秒
+        List<PatentCell> patentCells =new ArrayList<>();
+        for(int i=0;i<4800;i+=1600){
+            String js ="document.getElementsByClassName('sidebar-table__right')[0].scrollBy(0, "+i+")";
+            ((JavascriptExecutor) driver).executeScript(js);
+            TimeUnit.MILLISECONDS.sleep(1000);//毫秒
+            List<WebElement> ret2 =driver.findElements(By.className("pt-table__row--within-view"));
+            for (WebElement item: ret2) {
+                List<WebElement>  aLinks=item.findElements(By.tagName("a"));
+                PatentCell patentCell =new PatentCell();
+                aLinks.forEach(tem->{
+                    String type=  tem.getAttribute("data-link-type");
+                    if(type!=null&&type.equals("TITLE"))
+                    {
+                        String title=  tem.getAttribute("data-link-data");
+
+                        patentCell.setTitle(title);
+                    }
+                    else if(type!=null&&type.equals("PN"))
+                    {
+                        String url = tem.getAttribute("href");
+                        patentCell.setUrl(url);
+                        String patenNo=  tem.getAttribute("data-link-data");
+                        patentCell.setPatentNo(patenNo);
+
+                    }
+                    else if(type!=null&&type.equals("ANC"))
+                    {
+                        String applications=  tem.getAttribute("data-link-data");
+                        patentCell.setApplications(applications);
+                    }
+
+                });
+                String  legal =   driver.findElement(By.className("legal-tag__LEGAL_STATUS")).getText();
+                patentCell.setLegal(legal);
+                patentCells.add(patentCell);
+
+            }
+        }
+
+
+
+        // 5.退出浏览器
+//        driver.quit();
+        return patentCells;
+    }
+
+}

+ 30 - 0
src/main/java/com/example/demo/domain/PatentCell.java

@@ -0,0 +1,30 @@
+package com.example.demo.domain;
+
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * <p>
+ * 管理员表
+ * </p>
+ *
+ * @author 王岩
+ * @since 2022-03-25
+ */
+@Data
+
+/*数据库中的表对应的类
+ */
+public class PatentCell  {
+
+    /**
+     * 管理员用户名
+     */
+    private String patentNo;
+    private String title;
+    private String applications;
+    private String legal;
+    private String url;
+}

+ 2 - 0
src/main/resources/application.yml

@@ -0,0 +1,2 @@
+server:
+  port: 8111

BIN
src/main/resources/chromedriver.exe


+ 13 - 0
src/test/java/com/example/demo/DemoApplicationTests.java

@@ -0,0 +1,13 @@
+package com.example.demo;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class DemoApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}