0

i have some problem with my code. i am trying to open url and click element but i get 400 bad reques here is my code:

    def had_val(url,ip,num):
        driver = webdriver.Chrome('chromedriver')
        driver.header_overrides = {
        'USER-AGENT':'Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/103.0.5060.63 Mobile/15E148 Safari/604.1',
        'X-FORWARDED-FOR':str(ip),
        'msisdn':str(num),
        'Access-Control-Allow-Credentials':'True',
        'Access-Control-Allow-Headers':'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With',
        'Access-Control-Allow-Methods':'POST, GET, OPTIONS, DELETE, PUT',
        'Access-Control-Max-Age':'3600',
        'Cache-Control':'no-cache, must-revalidate, private',
        'X-FRAME-OPTIONS':'SAMEORIGIN'
        }
        time.sleep(3)
        driver.get(url)
        try :
            driver.find_element(by=By.XPATH,value='//*[@id="submitbtn"]').click()
            driver.implicitly_wait(10)
        except NoSuchElementException as exception:
            print("Button not found and test failed")
    
        time.sleep(10)
        driver.quit()
    
    
    my_file = open('http_proxies.txt')
    all_the_lines = my_file.readlines()
    ip_range = []
    for i in all_the_lines:
        ip_range.append(str(i))
        
        
    def pass_data():
        urls= 'https://affnet.gotrackier.com/t/MjM1XzI4Mg/?p1={tid}'
        wb = openpyxl.load_workbook("Book2.xlsx")
        sheet = wb.active
        m_row = sheet.max_row
        for row in sheet.iter_rows(min_row=1, min_col=1, max_row=m_row, max_col=1):
            for cell in row:
                secure_random = random.SystemRandom()
                random_ip = secure_random.choice(ip_range)
                print(random_ip,"and",cell.value)
            had_val(urls,random_ip,cell.value)
    pass_data() 
furas
  • 134,197
  • 12
  • 106
  • 148
rohan
  • 11
  • 1
  • alalways put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Jul 28 '22 at 09:05
  • maybe first use `print()` to see what url you try to connect. It seems you fogot to put value in place of `{tid}` in url. – furas Jul 28 '22 at 09:08
  • Update the question with the complete error stacktrace. – undetected Selenium Jul 28 '22 at 22:01

0 Answers0