下面几行代码为我提供了特定播放列表的源代码,并将所有url存储在一个变量“newlink”中。我想写一个循环,可以通过这个字符串的网址和存储的那些说'/看?在Python中,数组[0]会给出第一个链接,数组[1]会给出第二个链接,依此类推。最好的办法是什么?你知道吗
import re
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import requests
#Asks which playlist you want downloaded
print ('Which playlist do you want to download?')
playlist = input()
#Access my youtube playlists page
driver = webdriver.Chrome(executable_path='E:\chromedriver\chromedriver.exe')
driver.get("https://www.youtube.com/user/randomuser/playlists?sort=dd&view=1&shelf_id=0")
#Access the 'classic' playlist
if playlist == 'classic':
driver.find_element_by_xpath('//a[contains(text(), "classic")]').click()
newurl = driver.current_url
requrl = requests.get(newurl)
requrlcont = requrl.content
soup = BeautifulSoup(requrlcont, "html.parser")
for link in soup.find_all('a'):
newlink = link.get('href'))
此代码使用实际创建阵列的播放列表进行测试。你知道吗
输出
相关问题 更多 >
编程相关推荐