Python/Selenium组合多个列表并通过可见文本显示
我目前正在自学如何使用Python/Selenium 我有一个代码块,列出网页上所有可用的衬衫,然后列出所有可用的颜色,但我希望衬衫/颜色显示在一起,而不是两个单独的列表 以下是到目前为止我得到的信息:Python/Selenium组合多个列表并通过可见文本显示,python,list,selenium,selenium-webdriver,web-scraping,Python,List,Selenium,Selenium Webdriver,Web Scraping,我目前正在自学如何使用Python/Selenium 我有一个代码块,列出网页上所有可用的衬衫,然后列出所有可用的颜色,但我希望衬衫/颜色显示在一起,而不是两个单独的列表 以下是到目前为止我得到的信息: shirts = driver.find_elements_by_xpath("""//*[@id="container"]/article/div/h1/a""") for shirt in shirts: text = shirt.text print text colors
shirts = driver.find_elements_by_xpath("""//*[@id="container"]/article/div/h1/a""")
for shirt in shirts:
text = shirt.text
print text
colors = driver.find_elements_by_xpath("""//*[@id="container"]/article/div/p/a""")
for color in colors:
text = color.text
print text
以下是上述代码的结果:
Contrast Zip Up Hooded Sweatshirt
Contrast Zip Up Hooded Sweatshirt
Contrast Zip Up Hooded Sweatshirt
Contrast Zip Up Hooded Sweatshirt
Contrast Zip Up Hooded Sweatshirt
Contrast Zip Up Hooded Sweatshirt
Contrast Crewneck
Contrast Crewneck
Contrast Crewneck
Contrast Crewneck
Contrast Crewneck
Contrast Crewneck
Jet Sleeve Zip Up Hooded Sweatshirt
Jet Sleeve Zip Up Hooded Sweatshirt
Jet Sleeve Zip Up Hooded Sweatshirt
Jet Sleeve Zip Up Hooded Sweatshirt
Jet Sleeve Zip Up Hooded Sweatshirt
Navy
Red
Heather Grey
Dark Green
Light Brown
Black
Heather Grey
Light Brown
Black
Dark Green
Red
Navy
Violet
Light Pine
Black
White
Navy
使用方法:
shirts = driver.find_elements_by_xpath("//*[@id='container']/article/div/h1/a")
colors = driver.find_elements_by_xpath("//*[@id='container']/article/div/p/a")
for shirt, color in zip(shirts, colors):
shirt_text = shirt.text
color_text = color.text
print shirt_text, color_text