zoukankan      html  css  js  c++  java
  • selenium-百度新歌榜

    打开百度新歌榜, http://music.baidu.com/top/new

    在排名前50的歌曲中,找出其中排名上升的歌曲和演唱者

    from selenium import webdriver
    #chrome驱动 执行该步骤时selenium会去到指定路径将chrome driver执行起来
    driver = webdriver.Chrome(r"D:for myselfGoogleChromeApplicationchromedriver.exe")
    driver.implicitly_wait(10)#隐式等待
    #get方法 打开指定网址
    driver.get('http://music.baidu.com/top/new')

    div = driver.find_element_by_id("songListWrapper")
    ul = div.find_element_by_tag_name("ul")
    liList = ul.find_elements_by_tag_name('li')
    for li in liList:
    uptags = li.find_elements_by_class_name("up")
    if uptags:
    title = li.find_elements_by_class_name('song-title ')
    titleStr = title.find_element_by_tag_name("a").text

    authorsStr = li.find_element_by_class_name("author_list").text
    print('{:10s}:{}'.format(titleStr, authorsStr))#对齐格式 宽度为10

    driver.quit()
  • 相关阅读:
    access 连接数据库
    Debug 和 Release 的区别
    Centos
    打印画面
    读取文件夹以及消除
    常用的文件文件夹目录的操作函数
    db的操作
    从数据库取数据
    pdf文件的作成
    读取文件
  • 原文地址:https://www.cnblogs.com/iamshasha/p/11103422.html
Copyright © 2011-2022 走看看