我有一个web scraper,它像下面的例子一样返回我的值。你知道吗
# Other code above here.
test = []
results = driver.find_elements_by_css_selector("li.result_content")
for result in results:
# Other code about result.find_element_by_blah_blah
product_feature = result.find_element_by_class_name("prod-feature-icon")
for each_item in product_feature.find_elements_by_tag_name('img'):
zz = test.append(each_item.get_attribute('src')[34:-4]) # returning the values I want
print(zz)
上面的代码会这样打印结果:(这是我想要的值)
TCP_active
CI
DOH_active
TCP_active
CI
DOH
TCP
CI_active
DOH_active
我想取得以下成果:
[TCP_active, CI, DOH_active]
[TCP_active, CI, DOH]
[TCP, CI_active, DOH_active]
我该怎么做?你知道吗
我试过:
test.append(each_item.get_attribute('src')[34:-4])
但这给了我:
[TCP_active]
[TCP_active, CI]
[TCP_active, CI, DOH_active]
[TCP_active, CI, DOH_active, TCP]
...
希望我的解释清楚
不要
print
,而是将结果附加到列表中;外循环每次迭代一个新列表:如果需要,可以打印
features
,也可以打印test
,只是为了查看for
循环的每一级发生了什么。你知道吗好的,不完全确定您想要什么,但是下面的代码将给出您想要的输出:
如果要存储数据而不是打印数据,请使用类似以下内容的词典:
相关问题 更多 >
编程相关推荐