我是 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] 删除。
我来说两句