selenium获取微博用户粉丝数

selenum的安装

selenium文档

获取微博用户粉丝数

from selenium import webdriver
from time import sleep

wd = webdriver.Chrome("D:\program\chromedriver_win32\chromedriver.exe")
wd.maximize_window()
wd.implicitly_wait(15)

# 打开微博首页
wd.get("https://weibo.com/")
# 选中搜索框,输入检索内容,点击搜搜
searchInput = wd.find_element_by_css_selector('#weibo_top_public > div > div > div.gn_search_v2 > input')
searchBtn = wd.find_element_by_css_selector('#weibo_top_public > div > div > div.gn_search_v2 > a')

searchInput.send_keys("燕十八")
searchBtn.click()

# 进入新页面,设置新句柄
print(wd.title)

ysbLink = wd.find_element_by_css_selector('#pl_feed_main > div.m-wrap > div.m-con-r > div:nth-child(1) > div > div.card-content.s-pg12 > div:nth-child(1) > div.info > div > a')
ysbLink.click()

# 获取粉丝数目
follow = wd.find_element_by_css_selector('#Pl_Core_T8CustomTriColumn__3 > div > div > div > table > tbody > tr > td:nth-child(1) > a > strong')
fans = wd.find_element_by_css_selector('#Pl_Core_T8CustomTriColumn__3 > div > div > div > table > tbody > tr > td:nth-child(2) > a > strong')
weiboNum = wd.find_element_by_css_selector('#Pl_Core_T8CustomTriColumn__3 > div > div > div > table > tbody > tr > td:nth-child(3) > a > strong')

print("关注数:"+follow.text)
print("粉丝数:"+fans.text)
print("微博书:"+weiboNum.text)
sleep(3)
wd.close()

selenium获取微博用户粉丝数

相关推荐