Guest User

Untitled

a guest
Jan 18th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import sys
  2. import logging
  3. import datetime
  4. import selenium
  5. import bs4 as bs
  6. from selenium import webdriver
  7. from selenium.webdriver.common.keys import Keys
  8.  
  9. #############
  10. ###LOGGING###
  11. #############
  12. logging.basicConfig(level=logging.INFO, format = '%(asctime)s - %(levelname)s - %(message)s')
  13. logging.info('Date is ' + str(datetime.date.today()) + '. Datetime successfully imported.')
  14. logging.info('Selenium version is ' + str(selenium.__version__) +'. Selenium successfully imported.')
  15. logging.info('BS4 version is ' + bs.__version__ +'. BeautifulSoup successfully imported.')
  16.  
  17. #############
  18. ###CONNECT###
  19. #############
  20.  
  21. #login credentials
  22. username = 'data'
  23. password = 'data'
  24.  
  25. #instance of Chrome opens Librarika log in page
  26. browser = webdriver.Chrome()
  27. browser.implicitly_wait(10) # seconds
  28. browser.get("url")
  29.  
  30. #enters login credentials and clicks OK
  31. userElem = browser.find_element_by_xpath('''//*[@id="UserUsername"]''')
  32. userElem.clear()
  33. userElem.send_keys(username)
  34. passElem = browser.find_element_by_xpath('''//*[@id="UserPassword"]''')
  35. passElem.clear()
  36. passElem.send_keys(password)
  37. submitElem = browser.find_element_by_xpath('''//*[@id="UserLoginForm"]/div[2]/div/input''')
  38. submitElem.click()
  39.  
  40. #############
  41. ###PENDING###
  42. #############
  43.  
  44. #open pending in librarika and order by date
  45. #this way should avoid needing to write for more than one result page
  46. pendingURL = 'url/pending'
  47. browser.get(pendingURL)
  48. dateHeadElem = browser.find_element_by_xpath('''//*[@id="content"]/div/div[1]/div/table/tbody/tr[1]/th[2]/a''')
  49. dateHeadElem.click()
  50.  
  51. #return a count for rows and columns
  52. rowElem = browser.find_elements_by_xpath('''//*[@id="content"]/div/div[1]/div/table/tbody/tr''')
  53. rowLen = len(rowElem)
  54. colElem = browser.find_elements_by_xpath('''//*[@id="content"]/div/div[1]/div/table/tbody/tr[1]/th''')
  55. logging.info('There are ' + str(rowLen) + ' rows.')
  56. logging.info('There are ' + str(len(colElem)) + ' columns.')
  57.  
  58. #iterate through each row and check the start date
  59. for i in range(2,rowLen+1):
  60. loanDate = browser.find_element_by_xpath('''//*[@id="content"]/div/div[1]/div/table/tbody/tr['''+ str(i)+''']/td[2]''').text
  61. print(loanDate)
  62.  
  63.  
  64. #datetime formatting to match librarika
  65. #print(datetime.date.today().strftime('%b %d, %Y'))
Add Comment
Please, Sign In to add comment