I've been tkintering around web scraping and have come to a dead end. The code I have work for 1 iteration, however, it's unable to continuously parse(only copy ZipCode/Email each time after first iter)
I only need the E_MAIL & ZIPCODE values, so far I'm able to log into the webpage.
def login_portal():
# File
file = "C:\\exceldata.xlsx"
wb = load_workbook(file)
sheet = wb.active
.
.[Login section] .
.
sheet.columns[0]
sheet.columns[2]
sheet.columns[4]
firstRow = True
thirdRow = True
fifthRow = True
endMRN = True
for mrnNumber in sheet.columns[0]:
global firstRow
if firstRow:
firstRow = False
continue
cellValue = mrnNumber.value
ID_MRN = chrome_driver.find_element_by_id("PATH")
ID_MRN.send_keys(cellValue)
ID_MRN.send_keys(Keys.RETURN)
time.sleep(2)
#TODO: Click Link (href)/workaround ?
usrName = chrome_driver.find_element_by_xpath("PATH").click()
#TODO: Implement Security Questions - Postal Code
secQuestion = chrome_driver.find_element_by_xpath("PATH").click()
#TODO: Error Check if no Postal Code
#TODO: Select Postal Code from Excel
zipDone = True
for zipCode in sheet.columns[4]:
global fifthRow
if fifthRow:
fifthRow = False
continue
cellZip = zipCode.value
_zipCode = chrome_driver.find_element_by_id("PATH")
_zipCode.send_keys(cellZip)
time.sleep(2)
#TODO: Confirm Security Question Answer
secQuestionAns = chrome_driver.find_element_by_id("PATH")
secQuestionAns.send_keys(cellZip)
print("ZIPCODE CONFIRMED")
break
# TODO: Select Email Address from Excel
emailDone = True
for email in sheet.columns[2]:
global thirdRow
if thirdRow:
thirdRow = False
continue
emailAddr = email.value
recipientEmail = chrome_driver.find_element_by_xpath("PATH")
recipientEmail.send_keys(emailAddr)
time.sleep(2)
#TODO: Confirm Email Address
recipientEmailConfirm = chrome_driver.find_element_by_id("PATH")
recipientEmailConfirm.send_keys(emailAddr)
print("EMAIL ADDRESS CONFIRMED")
break
#TODO: Click Submit Button
submit = chrome_driver.find_element_by_id("PATH").click()
send_invite = chrome_driver.find_element_by_css_selector('PATH').click()
continue
if zipDone & emailDone:
zipDone = False
emailDone = False
break
#break
if endMRN:
endMRN = False
continue
break
However, once my code runs, it goes back to the initial start of the first FOR loop but the values are now ZIPCODE and E_MAIL. The If's at the end are my failed attempts at stopping the loop to start over. Can anyone see where my logic went off the deep end.. Essentially, I want the code to parse over MRN, Email and Zipcode and put the in the correct field on the web form. So far, I'm only getting: 123456789 jdoe@gmail.com 12345 on the next iteration (gives correct MRN#): 987654321 E_MAIL ZIPCODE
Thanks for any help.
Aucun commentaire:
Enregistrer un commentaire