letheashura 2019-11-12
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()
5.环境变量配置在linux系统下,需要将可执行文件配置到环境变量或将文件移动到属于环境变量的目录里面方法一:将文件移动到属于环境变量目录中sudo mv chromedriver /user/bin