-
Notifications
You must be signed in to change notification settings - Fork 0
/
payslip_fetcher.py
128 lines (118 loc) · 6.26 KB
/
payslip_fetcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.service import Service
import time
class PayslipFetcher:
def __init__(self):
self.options = Options()
self.options.add_argument("--headless=new")
self.options.add_argument("--no-sandbox")
self.options.add_argument("--disable-dev-shm-usage")
# Set User-Agent to mimic a Chrome browser on Windows
self.options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")
# Replace 'path_to_chromedriver' with the actual path to your local chromedriver.exe
self.driver = webdriver.Chrome(service=Service("chromedriver.exe"), options=self.options)
# Or use the remote webdriver for Selenium Grid
# self.driver = webdriver.Remote("http://192.168.10.32:4444/wd/hub", options=self.options)
self.wait = WebDriverWait(self.driver, 10)
def login(self, username, password):
self.driver.get('https://inpay.es.rsmuk.com/PayslipPortal4/Secured/Home.aspx')
# Wait for the login page to load
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'txtUserName')))
# Enter the username and password
self.driver.find_element(By.ID, 'txtUserName').send_keys(username)
self.driver.find_element(By.ID, 'txtPassword').send_keys(password)
# Find the login button and click it
self.driver.find_element(By.ID, 'cmdOK').click()
# Wait for the login process to complete
time.sleep(2)
def fetch_payslips(self):
# Go to the home page
self.driver.get('https://inpay.es.rsmuk.com/PayslipPortal4/Secured/Home.aspx')
# Create a list to store the payslip URLs
# Find all rows in the table and extract the payslip URLs
payslip_urls = [row.find_element(By.CSS_SELECTOR, "td a").get_attribute('href')
for row in self.driver.find_elements(By.CSS_SELECTOR, ".table.dataTable.no-footer tbody tr")
if row.find_elements(By.CSS_SELECTOR, "td a")]
# Iterate over the payslip URLs
for payslip_url in payslip_urls:
# Navigate to the payslip page
self.driver.get(payslip_url)
time.sleep(2)
# Wait for the PDF button to be clickable
pdf_button = WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((By.ID, '_ctl0_CpBody_ExportToPDFBtn'))
)
# Click the PDF button
pdf_button.click()
# Wait for the download to complete
time.sleep(2)
# Go back to the home page
self.driver.get('https://inpay.es.rsmuk.com/PayslipPortal4/Secured/Home.aspx')
def fetch_p60_forms(self):
# Go to the P60 forms page
self.driver.get('https://inpay.es.rsmuk.com/PayslipPortal4/Secured/P60Viewer.aspx')
# Wait for the page to load
time.sleep(2)
# Find the dropdown for selecting tax years and get all the options
options = self.driver.find_element(By.ID, '_ctl0_CpBody_ddlTaxYear').find_elements(By.TAG_NAME, 'option')
# Create a list of option tuples, excluding the currently selected option
option_list = [(option.get_attribute('value'), option.text)
for option in options]
# Iterate over the option list to fetch and save P60 forms
for option in option_list:
value, text = option
# Select the option to fetch the P60 form
tax_year_dropdown = self.driver.find_element(By.ID, '_ctl0_CpBody_ddlTaxYear')
tax_year_dropdown.send_keys(value)
# Wait for the form to load
time.sleep(2)
# Find the PDF button and click it to save the P60 form
pdf_button = self.driver.find_element(By.ID, '_ctl0_CpBody_ExportToPDFBtn')
pdf_button.click()
# Wait for the download to complete
time.sleep(2)
# Print the tax year and text for verification
print(f"Tax Year: {value}, Displayed Year: {text}")
# Go back to the P60 forms page
self.driver.get('https://inpay.es.rsmuk.com/PayslipPortal4/Secured/P60Viewer.aspx')
def fetch_p11d_forms(self):
# Go to the P11D forms page
self.driver.get('https://inpay.es.rsmuk.com/PayslipPortal4/Secured/P11DViewer.aspx')
# Wait for the page to load
time.sleep(2)
# Find the dropdown for selecting tax years and get all the options
options = self.driver.find_element(By.ID, '_ctl0_CpBody_ddlTaxYear').find_elements(By.TAG_NAME, 'option')
# Create a list of option tuples
option_list = [(option.get_attribute('value'), option.text) for option in options]
print(option_list)
# Iterate over the option list to fetch and save P11D forms
for option in option_list:
value, text = option
# Select the option to fetch the P11D form
tax_year_dropdown = Select(self.driver.find_element(By.ID, '_ctl0_CpBody_ddlTaxYear'))
tax_year_dropdown.select_by_value(value)
# Wait for the form to load
time.sleep(5)
# Find the PDF button and click it to save the P11D form
pdf_button = self.driver.find_element(By.ID, '_ctl0_CpBody_ExportToPDFBtn')
pdf_button.click()
# Wait for the download to complete
time.sleep(5)
# Print the tax year and text for verification
print(f"Tax Year: {text}")
# Go back to the P11D forms page
self.driver.get('https://inpay.es.rsmuk.com/PayslipPortal4/Secured/P11DViewer.aspx')
def quit(self):
self.driver.quit()
if __name__ == '__main__':
payslip_fetcher = PayslipFetcher()
payslip_fetcher.login('<replace-with-your-username>', '<replace-with-your-password>')
payslip_fetcher.fetch_payslips()
payslip_fetcher.fetch_p60_forms()
payslip_fetcher.fetch_p11d_forms()
payslip_fetcher.quit()