示例:
import itertools
color = ['Red','White','Blue']
shape = ['Circle','Square']
combo = list(itertools.product(color,shape))
print(combo)结果:[(‘红色’,‘圆形’),(‘红色’,‘正方形’),(‘白色’,‘正方形’),(‘白色’,‘正方形’),(‘蓝色’,‘圆形’),(‘蓝色’,‘正方形’)]
获得每种组合都很好用。我现在要做的是分别搜索每个组合。这就是我被卡住的地方。
示例:
for searches in combo:
driver.get("https://www.bing.com")
search = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#sb_form_q")))
search.send_keys(str(combo))
search.submit()结果是一次搜索所有组合,而不是在循环中单独搜索每个组合。我做错了什么?
发布于 2020-10-14 06:12:59
你也应该send_keys searches而不是combo。搜索将是一个元组,我假设您打算以"Red Circle“等形式发送关键字。
尝尝这个
import itertools
color = ['Red','White','Blue']
shape = ['Circle','Square']
combo = list(itertools.product(color,shape))
print(combo)
for searches in combo:
print(" ".join(searches))https://stackoverflow.com/questions/64343831
复制相似问题