Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/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:为什么map()函数会弄乱我的Web元素?_Python_Selenium_Dictionary - Fatal编程技术网

Python Selenium:为什么map()函数会弄乱我的Web元素?

Python Selenium:为什么map()函数会弄乱我的Web元素?,python,selenium,dictionary,Python,Selenium,Dictionary,使用Python 3.4/Selenium,您可以看到以下几行代码: get_stuff = driver.find_elements_by_xpath(stuffXpath) get_stuff1 = list(map(lambda x: x.get_attribute('href'), get_stuff)) get_stuff2 = map(lambda x: x.find_element_by_xpath('./img'), get_stuff) get_stuff3 = list(

使用Python 3.4/Selenium,您可以看到以下几行代码:

get_stuff = driver.find_elements_by_xpath(stuffXpath)

get_stuff1 = list(map(lambda x: x.get_attribute('href'), get_stuff))
get_stuff2 = map(lambda x: x.find_element_by_xpath('./img'), get_stuff)

get_stuff3 = list(map(lambda x: x.get_attribute('src'), get_stuff2))
get_stuff4 = list(map(lambda x: x.get_attribute('style'), get_stuff2))
问题是get_stuff3给了我想要的正确列表,但是get_stuff4是一个空列表

如果我切换最后两行,那么get_stuff4会给我想要的,但是现在get_stuff3是一个空列表

我到处都找过了,但运气不好

为什么map()会对我的列表执行此操作

我怎么修理它

现在我已经做了这个来修复它,但它并不优雅:

get_stuff2 = map(lambda x: x.find_element_by_xpath('./img'), get_stuff)
get_stuff2a = map(lambda x: x.find_element_by_xpath('./img'), get_stuff)

get_stuff3 = list(map(lambda x: x.get_attribute('src'), get_stuff2))
get_stuff4 = list(map(lambda x: x.get_attribute('style'), get_stuff2a))

为什么这个问题没有得到答复?仍然没有答复。也许应该在某处有一个突出的按钮,标明“如何获得回复”。