打开网易云自动登录,查找指定歌曲并播放
练习selenium的元素定位,以及等待方式
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76# -*- coding: utf-8 -*- # @Time : 2020/11/16 16:56 # @Author : YOGA # @File : 网易云自动登录.py # @Software: PyCharm import time from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get("https://music.163.com/") #全屏网页 driver.maximize_window() # time.sleep(3) ''' selenium的三种等待方式: 1、强制等待 time.sleep(seconds) 2、隐式等待:等待页面全部加载完就执行 driver.implicitly_wait(max_seconds) 参数为最多等待的时间 3、显式等待:显示等待是针对某一个元素进行相关等待判定 element = WebDriverWait(driver, 5, 0.5).until(EC.presence_of_element_located((By.ID, 'su'))) 一共等待 5 秒钟,每 0.5s 找一次,直到通过 ID 找到 ''' driver.implicitly_wait() #点击页面登录 driver.find_element_by_xpath("//a[text()='登录']").click() # time.sleep(3) #选择其他方式登录 driver.find_element_by_xpath("//a[text()='选择其他登录模式']").click() # time.sleep(3) #勾选同意协议 driver.find_element_by_xpath("//input[@id='j-official-terms']").click() # time.sleep(3) #选择手机登录 driver.find_element_by_xpath("//a[@data-type='mobile']").click() # time.sleep(3) #输入用户名和密码 driver.find_element_by_xpath("//input[@id='p']").send_keys("15673161596") driver.find_element_by_xpath("//input[@id='pw']").send_keys("orangewyj523") # time.sleep(3) #取消选择自动登录 driver.find_element_by_xpath("//input[@type='checkbox']").click() # time.sleep(3) #点击登录 driver.find_element_by_xpath("//a[@class='j-primary u-btn2 u-btn2-2']").click() # time.sleep(3) driver.find_element_by_id('srch').send_keys("心恋") driver.find_element_by_id('srch').send_keys(Keys.ENTER) # time.sleep(5) ''' 注意注意注意注意这个是重点!!! 因为搜索之后跳转到了新的页面,所以必须要driver.switch_to.frame!!! ''' driver.switch_to.frame("g_iframe") ele = driver.find_element_by_xpath('//*[@id="song_1487511998"]') # time.sleep(2) # driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[2]/div/div/div[1]/div[1]/div/a').click() # play = driver.find_element_by_id("song_1487511998") print(ele) # time.sleep(2) ele.click() # driver.find_element_by_class_name('ply').click()
最后
以上就是暴躁时光最近收集整理的关于python+selenium网易云音乐自动登录并查找歌曲播放的全部内容,更多相关python+selenium网易云音乐自动登录并查找歌曲播放内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复