【发布时间】:2020-09-24 18:47:09
【问题描述】:
#iFrame
driver.switch_to.frame(driver.find_element_by_css_selector("#iFrameResizer0"))
#Findings elements
time.sleep(2) #Sleep to avoid 'laiks' error?
laiks = driver.find_elements_by_class_name("event-date-time__time")
time.sleep(3)
speles = driver.find_elements_by_class_name("event-block-row__name")
time.sleep(4)
odds = driver.find_elements_by_class_name("odd__value")
if laiks and speles and odds is not None:
print("Plkst., Spēlētāji, Koeficients:")
#Create datas.txt, write into it
with open("datas.txt", "w") as output:
for viss in laiks + speles + odds:
#Print in console the above
print(viss.text);
#Write in output file
output.write(viss.text + " | ")
这会在 data.txt 文件中生成以下内容:
23:30 | 23:30 | 22:00 | 22:30 | 23:30 | 08:00 | 11:00 | 14:00 | 16:00 | 15:00 | 18:30 | 22:00 | 15:00 | 20:00 | Havan Liberty - Isurus Gaming | Boom.id - Sharks Esports | Sector One - 4Elements Esports | Sprout - Divizon | Gamefist - Jointheforce | Touch The Crown - Unicorns of Love | Unicorns of Love - Touch The Crown | Huat Zai - After Gaming | Beyond Esports - Zigma | Tiger - Invictus Gaming | C0ntact Gaming - Mousesports | North - Sprout | Natus Vincere - Mousesports | Complexity Gaming - ENCE | BIG - Team Spirit | Astralis - Heroic | Evil Geniuses - Furia Esports | Liquid - 100 Thieves | 2.08 | 1.67 | 1.48 | 2.42 | 3.70 | 1.25 |
但是,这不是预期的结果,而且很难理解。 “laiks”的第一个值表示“speles”的第一个值和前两个“odds”值。
23:30 | Havan Liberty - Isurus Gaming | 2.08 | 1.67 |
23:30 | Boom.id - Sharks Esports | 1.48 | 2.42 |
我该怎么做?
【问题讨论】:
-
你好像在找
zip但是这里有很多不相关的代码。请edit 将您的问题简化为minimal reproducible example,这不需要我们安装 Chrome 驱动程序等来解决一个简单的 Python 问题。 -
这样的? ideone.com/QOE9Tl
-
@tripleee 这是我正在寻找的结果。据我了解, zip() 函数将第一个“laiks”与第一个“speles”和第一个“odds”配对。然后是第二个“laiks”,第二个“speles”和第二个“odds”等等,对吧?问题是,当我将 zip 函数放在我的 .py 文件中时,它会给我一个很长的“
-
没有看到代码和实际的错误信息,我能说的不多。可能会在您当前的尝试中发布一个新问题。