前置准备
1.准备Python环境,安装selenium(运行命令:pip install selenium==4.16.0);
2.准备谷歌浏览器以及与浏览器同版本的webdriver(driver下载地址),将driver文件与此.py文件放在一起,并将浏览器chrome.exe路径赋给option.binary_location。
代码
import random
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
option = Options()
option.binary_location = r'.\doc\Chrome\Application\chrome.exe'
choujiang_url = 'https://www.weibo.com/5692100100/NC99xE0pd#repost'
# 打开浏览器
with webdriver.Chrome(option) as driver:
driver.get('https://weibo.com/')
print