|
@@ -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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|