Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python/Selenium组合多个列表并通过可见文本显示_Python_List_Selenium_Selenium Webdriver_Web Scraping - Fatal编程技术网

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

我目前正在自学如何使用Python/Selenium

我有一个代码块,列出网页上所有可用的衬衫,然后列出所有可用的颜色,但我希望衬衫/颜色显示在一起,而不是两个单独的列表

以下是到目前为止我得到的信息:

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