如何在python中按顺序打开列表中的所有链接?

ludon5681

我是 python 的完全新手,并试图编写代码来一次打开一个列表中的所有链接。无论我做什么尝试排除故障,我都会遇到不同的错误,并且想知道我的方法是否有问题。

这是我的代码:

    import time
    import requests
    
            links = [
            "https://www.cbc.ca/arts/montreal-was-home-to-the-first-known-queer-magazine-in-north-america-from-1918-1920-1.6069620",
            "https://www.cbc.ca/archives/not-a-good-time-for-newspapers-the-1992-edition-1.5604471",
            "https://www.cbc.ca/archives/car-phones-helped-get-the-job-done-in-1990-1.5166262",
            "https://www.cbc.ca/news/canada/nova-scotia/africville-documentary-irvine-carvery-daisy-carvery-halifax-1.5936410",
            "https://www.cbc.ca/news/entertainment/frank-bonner-actor-herb-tarlek-dead-1.6070564",
            "https://www.cbc.ca/archives/drinks-of-the-70s-80s-90s-1.6060609",
            "https://www.cbc.ca/archives/when-goat-cheese-got-to-be-quite-a-fad-in-canada-1.5606611",
            "https://newsinteractives.cbc.ca/longform/overtime-in-vancouver",
            "https://www.cbc.ca/archives/it-wasn-t-skateboarding-in-1965-it-was-skurfing-1.5600339",
            "https://www.cbc.ca/archives/that-time-former-ndp-leader-ed-broadbent-made-a-comeback-with-a-rap-video-1.5160702",
            "https://www.cbc.ca/news/canada/sudbury/bowie-painting-northern-ontario-1.6064962",
            "https://www.cbc.ca/archives/the-meteorite-that-startled-cows-and-quebecers-in-1994-1.5598277",
            "https://www.cbc.ca/archives/when-2-prime-ministers-swapped-houses-1.5174481",
            "https://www.cbc.ca/news/entertainment/ned-beatty-obit-1.6064539",
            "https://www.cbc.ca/news/canada/north/styrofoam-igloos-kinngait-1.6060597",
            "https://www.cbc.ca/radio/spark/something-s-rotten-in-the-state-of-the-internet-and-archivists-are-worried-1.6047113",
            "https://www.cbc.ca/news/canada/nova-scotia/tram-tracks-uncovered-spring-garden-road-1.6063126",
            "https://www.cbc.ca/radio/unreserved/what-happens-when-hidden-histories-become-a-national-conversation-1.6059520/the-indigenous-connection-to-the-underground-railroad-1.6061957",
            "https://www.cbc.ca/archives/cancon-junos-radio-music-industry-1.6050466",
            "https://www.cbc.ca/archives/taking-the-census-wasn-t-easy-in-1961-1.5158058",
            "https://www.cbc.ca/news/canada/montreal/first-person-indigenous-representation-museums-culture-history-1.6059501",
            "https://www.cbc.ca/news/canada/ottawa/mcarthur-bowling-alley-closed-1.6060365",
            "https://www.cbc.ca/arts/how-the-rosie-o-donnell-show-changed-celebrity-culture-forever-1.6059882",
            "https://www.cbc.ca/archives/when-canadian-wine-cost-too-much-for-canadian-consumers-1.5596783",
        ]
        
        i = 0
        
        k = 24
        
        from selenium import webdriver
        url = links[i]
        driver = webdriver.Firefox(executable_path=r'geckodriver.exe')
        driver.get(url)
        time.sleep(5)
        
        for i in links:
            if i <= k:
                continue
约阿齐马斯

以下应该工作:

import time
import requests

    links = [
    "https://www.cbc.ca/arts/montreal-was-home-to-the-first-known-queer-magazine-in-north-america-from-1918-1920-1.6069620",
    "https://www.cbc.ca/archives/not-a-good-time-for-newspapers-the-1992-edition-1.5604471",
    "https://www.cbc.ca/archives/car-phones-helped-get-the-job-done-in-1990-1.5166262",
    "https://www.cbc.ca/news/canada/nova-scotia/africville-documentary-irvine-carvery-daisy-carvery-halifax-1.5936410",
    "https://www.cbc.ca/news/entertainment/frank-bonner-actor-herb-tarlek-dead-1.6070564",
    "https://www.cbc.ca/archives/drinks-of-the-70s-80s-90s-1.6060609",
    "https://www.cbc.ca/archives/when-goat-cheese-got-to-be-quite-a-fad-in-canada-1.5606611",
    "https://newsinteractives.cbc.ca/longform/overtime-in-vancouver",
    "https://www.cbc.ca/archives/it-wasn-t-skateboarding-in-1965-it-was-skurfing-1.5600339",
    "https://www.cbc.ca/archives/that-time-former-ndp-leader-ed-broadbent-made-a-comeback-with-a-rap-video-1.5160702",
    "https://www.cbc.ca/news/canada/sudbury/bowie-painting-northern-ontario-1.6064962",
    "https://www.cbc.ca/archives/the-meteorite-that-startled-cows-and-quebecers-in-1994-1.5598277",
    "https://www.cbc.ca/archives/when-2-prime-ministers-swapped-houses-1.5174481",
    "https://www.cbc.ca/news/entertainment/ned-beatty-obit-1.6064539",
    "https://www.cbc.ca/news/canada/north/styrofoam-igloos-kinngait-1.6060597",
    "https://www.cbc.ca/radio/spark/something-s-rotten-in-the-state-of-the-internet-and-archivists-are-worried-1.6047113",
    "https://www.cbc.ca/news/canada/nova-scotia/tram-tracks-uncovered-spring-garden-road-1.6063126",
    "https://www.cbc.ca/radio/unreserved/what-happens-when-hidden-histories-become-a-national-conversation-1.6059520/the-indigenous-connection-to-the-underground-railroad-1.6061957",
    "https://www.cbc.ca/archives/cancon-junos-radio-music-industry-1.6050466",
    "https://www.cbc.ca/archives/taking-the-census-wasn-t-easy-in-1961-1.5158058",
    "https://www.cbc.ca/news/canada/montreal/first-person-indigenous-representation-museums-culture-history-1.6059501",
    "https://www.cbc.ca/news/canada/ottawa/mcarthur-bowling-alley-closed-1.6060365",
    "https://www.cbc.ca/arts/how-the-rosie-o-donnell-show-changed-celebrity-culture-forever-1.6059882",
    "https://www.cbc.ca/archives/when-canadian-wine-cost-too-much-for-canadian-consumers-1.5596783",
]


from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'geckodriver.exe')
for i in links:
    driver.get(i)
    time.sleep(5)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在 Python 中按顺序获取列表元素的所有串联?

如何使用CompletableFuture打开列表中的所有结果并将其收集到线程中?

如何在python中按顺序对列表进行排序?

如何在(python)列表中按顺序替换数字

如何在python中按顺序获取类的所有成员?

如何在python中打开目录中的所有文件?

如何在C中按字母顺序对链接列表进行排序

如何在React中创建折叠展开列表

如何在新标签页中打开iframe中的所有链接

如何在新标签页中打开块中的所有链接

如何在Python3中找到按数字顺序排列的列表中的数字?

R-如何展开列表中的每个项目以包括最早日期和今天之间的所有日期

如何在R中按组对所有顺序列对进行测试

如何在一行中按顺序对所有项目的总金额进行分组

如何在 google doc 的 google 脚本中替换按字母顺序排列的所有元素

如何在Python中以相同顺序将一个列表中的所有整数与长度不同的另一个列表中的整数相加?

如何删除链接<a>和它在<li>中的列表项之间的所有填充?还是...单击<li>打开其中的链接?

如何在列表中按顺序修改和添加单词 - Python

如何在ListView项中展开列?

如何用python中的顺序替换列表中的所有项目?

在 Python 中,如何按顺序生成一串 0 和 1 的所有排列?

如何在链接列表中按属性删除对象?

如何从具有子列表的列表中获取值并将所有值按顺序存储在另一个列表中

如何在命令行中获取所有打开的窗口的列表?

如何在NotePad ++的单个下拉列表中合并所有打开的选项卡?

在列表中解开列表

在列表中展开列表

如何在postgres sequelize中按位置获取所有用户列表组?

JavaScript:打开列表中的第一个链接,等待,然后打开下一个链接