我有一个文本文件,其中包含四个地址的列表。请参见下面的屏幕截图:在我的硒刮刀中,我将每个地址作为密钥传递。addresselements.send_keys(lines)。运行 selenium 驱动程序时,它仅从我的文本文件和浏览器中获取第一个地址。这是我的完整代码的摘要:from selenium import webdriverdriver = webdriver.Chromeurl ="my terget url"driver.get(url) addressElement = driver.find_elements_by_css_selector('#search-input-adresse') #impoting address from text filef = open('address.txt')lines = f.readline() for addresselements in addressElement: addresselements.send_keys(lines) #enter your address addresselements.send_keys(Keys.ENTER)我如何将所有地址一一循环。我也尝试过这段代码但没有用f = open('address.txt')lines = f.readline()for line in f: for addresselements in addressElement: addresselements.send_keys(lines) #enter your address addresselements.send_keys(Keys.ENTER)
1 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
readline()只读取一行,readlines()如果您想从文件中获取所有数据,则需要使用。
with open('address.txt', 'r') as file:
for line in file.readlines():
for addresselements in addressElement:
addresselements.send_keys(line) #enter your address
addresselements.send_keys(Keys.ENTER)
添加回答
举报
0/150
提交
取消