selenium获取微博用户粉丝数

无人久伴 提交于 2020-01-24 22:06:54

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()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!