有没有办法循环mysql数据并执行它

时间:2019-06-12 03:17:41

标签: python mysql-connector mysql-connector-python

当我尝试执行时,它只会循环执行,而不会执行到webdriver浏览器 有没有办法遍历并执行从mysql数据库到python的每个数据?

import sys
import time
from selenium import webdriver
import mysql.connector
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

koneksi=mysql.connector.connect(host='192.168.100.9',user='streamga',password='ownerpp170896',db='theprimebot',port='3306')
config=koneksi.cursor()

config.execute("select * from data_user")
rows=config.fetchall()

for r in rows :
    phonenum={r[0]}
    passwordStr={r[1]}

#i want to make every looping inserted to here
browser = webdriver.Firefox()
browser.get(("http://192.168.100.9/pytontest"))
phone = browser.find_element_by_id('popupPhone')
phone.send_keys(phonenum)
pass_login = browser.find_element_by_id('popupPassword')
pass_login.send_keys(passwordStr)
loginbutton = browser.find_element_by_id('popupLoginBtn')
loginbutton.click()
time.sleep(5)

1 个答案:

答案 0 :(得分:0)

由于没有可用的回溯,因此您可以参考以下一些建议

  1. 确保已安装firefox Web驱动程序

  2. 不应设置输入(不像{...}那样),而应设置字符串

  3. 硒逻辑应成为循环的一部分

  4. 在每个循环结束时关闭浏览器(如果适用)

for r in rows :
    phonenum=r[0]
    passwordStr=r[1]
    browser = webdriver.Firefox("/path/to/webdriver")
    browser.get(("http://192.168.100.9/pytontest"))
    phone = browser.find_element_by_id('popupPhone')
    phone.send_keys(phonenum)
    pass_login = browser.find_element_by_id('popupPassword')
    pass_login.send_keys(passwordStr)
    loginbutton = browser.find_element_by_id('popupLoginBtn')
    loginbutton.click()
    browser.quit()
    time.sleep(5)