ifme

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

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2021-08-30
  • 2021-10-03
  • 2022-02-23
  • 2021-05-02
  • 2022-01-09
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-06-15
  • 2021-06-12
相关资源
相似解决方案