首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Python/Selenium中缩进一些比较复杂的代码块?

如何在Python/Selenium中缩进一些比较复杂的代码块?
EN

Stack Overflow用户
提问于 2018-05-20 23:55:20
回答 1查看 54关注 0票数 0

我对python/selenium相当陌生,我对如何缩进这段特定的代码有个问题。代码:

代码语言:javascript
复制
articles = driver.find_elements_by_tag_name('article')
for article in articles:
ActionChains(driver).move_to_element(article).perform()
if article.find_element_by_tag_name('a').text == "sold out":
     print("sold out")
else:
    print("available")
        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
            link = article.find_element_by_xpath('div/a').get_attribute('href')
            print(link)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-21 00:13:40

代码语言:javascript
复制
articles = driver.find_elements_by_tag_name('article')
for article in articles:
    ActionChains(driver).move_to_element(article).perform()
    if article.find_element_by_tag_name('a').text == "sold out":
         print("sold out")
    else:
        print("available")
        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
            link = article.find_element_by_xpath('div/a').get_attribute('href')
            print(link)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50440426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档