我正在使用熊猫读取包含IP地址及其各自位置/名称的csv文件。当我使用硒浏览要刮除的IP列表时,没有附加它们的相应名称,而是为每个位置/名称重复列表中的第一个IP。
import pandas as pd
file1 = pd.read_csv('file.csv', delimiter=',')
urls = file1[['IP']]
locos = file1[['LOCATION']]
urlss = []
overviewss = []
location = []
for row in file1.itertuples(index=True, name='Pandas'):
urls = getattr(row, "IP").strip()
locos = getattr(row, "LOCATION").strip()
overviews = getattr(row, "IP").strip()
urlss.append('https://' + urls)
overviewss.append('https://' + urls + '/overview.asp')
location.append(locos)
#Open CPE admin page and login
options = webdriver.ChromeOptions() #Enable Chrome driver options
options.add_argument('headless') #No browser is opened to view process
options.add_experimental_option('excludeSwitches', ['enable-logging']) #Disable Devtools log message
browser = webdriver.Chrome(r'C:\chromedriver\chromedriver.exe', options=options)
for url,overviews in zip(urlss, overviewss):
try:
browser.get(url)
预期结果: 192.168.1.1悉尼 192.168.1.2纽约 192.168.1.3拉斯维加斯
实际结果: 192.168.1.1悉尼 192.168.1.1纽约 192.168.1.1拉斯维加斯