我对 Python 很陌生。我正在尝试抓取一个网站,并为此创建了一个小代码:
select = Select(character.find_element_by_id('character-template-choice'))
options = select.options
for index in range(0, len(options) - 0):
select.select_by_index(index)
option1 = character.find_elements_by_class_name('pc-stat-value')
power = []
for c in option1:
power.append("Power:" + c.text)
option2 = character.find_elements_by_class_name(
'unit-stat-group-stat-label')
skills = []
for a in option2:
skills.append(a.text)
option3 = character.find_elements_by_class_name(
'unit-stat-group-stat-value')
values = []
for b in option3:
values.append(b.text)
test = [power, skills, values]
print(test)
df = pd.DataFrame(test).T
df.to_csv('test2.csv', index=False, header=False)
我遇到的问题是,当我尝试将列表的“测试”列表导出到 csv 时,我只得到最后一次迭代。我想获取每次迭代的数据,但我不知道该怎么做。有人能帮我吗?
谢谢