Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 KB | None | 0 0
  1. import java.awt.Toolkit;
  2. import java.awt.datatransfer.Clipboard;
  3. import java.awt.datatransfer.StringSelection;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.IOException;
  8. import java.io.PrintWriter;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import java.util.concurrent.TimeUnit;
  12.  
  13. import org.apache.poi.EncryptedDocumentException;
  14. import org.apache.poi.ss.usermodel.Cell;
  15. import org.apache.poi.ss.usermodel.Row;
  16. import org.apache.poi.ss.usermodel.Sheet;
  17. import org.apache.poi.ss.usermodel.Workbook;
  18. import org.apache.poi.ss.usermodel.WorkbookFactory;
  19. import org.jsoup.Jsoup;
  20. import org.junit.Assert;
  21. import org.openqa.selenium.By;
  22. import org.openqa.selenium.JavascriptExecutor;
  23. import org.openqa.selenium.Keys;
  24. import org.openqa.selenium.WebDriver;
  25. import org.openqa.selenium.WebElement;
  26. import org.openqa.selenium.chrome.ChromeDriver;
  27. import org.openqa.selenium.support.ui.ExpectedConditions;
  28. import org.openqa.selenium.support.ui.Select;
  29. import org.openqa.selenium.support.ui.WebDriverWait;
  30.  
  31. public class scopus {
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. public static void main(String[] args) throws EncryptedDocumentException, FileNotFoundException, IOException, InterruptedException {
  39. // TODO Auto-generated method stub
  40.  
  41.  
  42. List<String> ISSN_List = new ArrayList<>();
  43. List<Integer> checkpoint = new ArrayList<>();
  44. List<String> issn = new ArrayList<>();
  45.  
  46. int cp =0;
  47. int begin = 0;
  48. String cellData;
  49. String search_year ="2012";
  50. String total_citation ="";
  51. String email_notification= " no email sent";
  52. String file_name = "";
  53.  
  54. String saved_issn="";
  55. String enter_email = "30049683@westernsydney.edu.au";
  56. int cumulative_count = 10000;
  57. String FoR ="";
  58.  
  59. File file = new File("Selenium.xlsx");
  60. Workbook wb = WorkbookFactory.create(new FileInputStream(file));
  61. Sheet sheet = wb.getSheetAt(0);
  62.  
  63. FoR = wb.getSheetAt(0).getRow(6).getCell(6).toString();
  64.  
  65. if (file.isFile() && file.exists()) {
  66. System.out.println("Selenium.xlsx open");
  67. }
  68. else {
  69. System.out.println("Selenium.xlsx either not exist"
  70. + " or can't open");
  71. }
  72.  
  73.  
  74.  
  75. //J = row Number
  76. for (int j=6; j< sheet.getLastRowNum(); j++) {
  77. //Using 2 rows and ID's to compare for duplicate ID's
  78. Row row = sheet.getRow(j);
  79. Row row2 = sheet.getRow(j-1);
  80. Cell id = row.getCell(0);
  81. Cell id2= row2.getCell(0);
  82. //Grabs Cumulative Column
  83. Cell cumulative = row.getCell(3);
  84. //Grabs ISSN Column
  85. Cell issn_col = row.getCell(8);
  86.  
  87. cp++;
  88. //Checks if the Cumulative count is equal to or greater than every 10k articles
  89. if(cumulative.getNumericCellValue()>= cumulative_count) {
  90. //Checks straddle ID's, if so create a checkpoint within the ArrayList
  91. if(id.getStringCellValue() != id2.getStringCellValue()) {
  92. cumulative_count = cumulative_count + 10000;
  93. checkpoint.add(cp);
  94. }
  95. }
  96.  
  97. //Grabs the Value of the ISSN and adds it to the List
  98. cellData = issn_col.getStringCellValue();
  99. ISSN_List.add(cellData);
  100. }
  101. //Finalize The Checkpoint
  102. checkpoint.add(cp);
  103.  
  104.  
  105. for(int i=0;i<checkpoint.size();i++) {
  106. //Creates a temporary List array, from one checkpoint to another
  107. List <String> temp = ISSN_List.subList(begin, checkpoint.get(i));
  108. begin = checkpoint.get(i);
  109. //Stores into a string
  110. String temp_S = temp.toString();
  111. temp_S = temp_S.substring(1, temp_S.length() - 1);
  112.  
  113. //Stores the checkpoint in one index position
  114. issn.add(temp_S);
  115. }
  116.  
  117.  
  118.  
  119.  
  120. for(int i = 0; i<checkpoint.size();i++) {
  121. saved_issn = issn.get(i).toString();
  122. saved_issn = saved_issn.substring(1, saved_issn.length());
  123.  
  124. System.out.println("saved:"+saved_issn);
  125.  
  126.  
  127. System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver.exe");
  128. String url ="https://www.scopus.com/customer/authenticate/loginfull.uri";
  129. String advanced_tab = "https://www.scopus.com/search/form.uri?display=advanced&origin=searchbasic&txGid=526775849ea4aa06b2c4852684f5e249";
  130. WebDriver driver = new ChromeDriver();
  131.  
  132. driver.get(url);
  133.  
  134. try{
  135. Assert.assertEquals(url, driver.getCurrentUrl());
  136. System.out.println("Navigated to correct webpage");
  137. }
  138. catch(Throwable pageNavigationError){
  139. System.out.println("Didn't navigate to correct webpage");
  140. }
  141.  
  142.  
  143. //Login to the account
  144. WebElement username = driver.findElement(By.id("username"));
  145. username.sendKeys(enter_email);
  146. WebElement password = driver.findElement(By.id("password-input-password"));
  147. password.sendKeys("westernsydney");
  148. WebElement submit_password = driver.findElement(By.id("login_submit_btn"));
  149. submit_password.submit();
  150.  
  151.  
  152.  
  153. //Grabs both Years for the found ISSNs
  154. for(int year =0; year<1; year++) {
  155. if(year ==0) saved_issn = saved_issn + " AND ( LIMIT-TO ( PUBYEAR , "+search_year+" ) ) AND ( LIMIT-TO ( DOCTYPE , \"ar\" ) OR LIMIT-TO ( DOCTYPE , \"re\" )";
  156.  
  157. driver.get(advanced_tab);
  158.  
  159. try{
  160. Assert.assertEquals(advanced_tab, driver.getCurrentUrl());
  161. System.out.println("Navigated to correct webpage");
  162. }
  163. catch(Throwable pageNavigationError){
  164. System.out.println("Didn't navigate to correct webpage");
  165. }
  166.  
  167.  
  168. setClipboardContents(saved_issn);
  169. driver.findElement(By.id("searchfield")).sendKeys(Keys.CONTROL +"v");
  170. driver.findElement(By.id("searchfield")).sendKeys(Keys.RETURN);
  171.  
  172.  
  173.  
  174. //Checks the All the CheckBoxes
  175. if ( !driver.findElement(By.id("selectAllCheck")).isSelected() )
  176. {
  177. driver.findElement(By.id("selectAllCheck")).click();
  178. }
  179.  
  180.  
  181.  
  182. //Clicks on View Citation Overview
  183. WebElement view_citation = driver.findElement(By.id("ctoDocResultLink"));
  184. view_citation.click();
  185.  
  186.  
  187.  
  188. setClipboardContents(enter_email);
  189. WebDriverWait wait = new WebDriverWait(driver, 10);
  190.  
  191. String no_of_articles = driver.findElement(By.className("resultsCount")).getText();
  192.  
  193. try{
  194. wait.until(ExpectedConditions.elementToBeClickable(By.id("closeBigCTODialog")));
  195. driver.findElement(By.id("emailCTO")).sendKeys(Keys.CONTROL +"v");
  196. //Waits for email to be sent properly
  197. Thread.sleep(1000);
  198. driver.findElement(By.id("emailCTO")).sendKeys(Keys.RETURN);
  199. total_citation = "unkown";
  200. file_name= FoR +" "+ search_year+" "+ no_of_articles +".txt";
  201.  
  202. }
  203. catch(Throwable pageNavigationError){
  204. //Grab FOR, ALL Publications, Citations and save it in.....
  205. total_citation = driver.findElement(By.id("grandtotal")).getText();
  206. file_name= FoR +" "+ search_year+" "+ no_of_articles +" "+email_notification+".txt";
  207.  
  208.  
  209. }
  210.  
  211. PrintWriter writer = new PrintWriter(file_name, "UTF-8");
  212. writer.println("Year, "+ "No of articles,"+ " total_citations ");
  213. writer.println(search_year+", "+no_of_articles+", "+total_citation);
  214. writer.close();
  215.  
  216. }
  217. driver.quit();
  218. }
  219.  
  220. }
  221.  
  222.  
  223. public static void setClipboardContents(String text) {
  224. StringSelection stringSelection = new StringSelection( text );
  225. Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  226. clipboard.setContents(stringSelection, null);
  227. }
  228.  
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement