爬取某人的微博数据,把某人所有时间段的微博数据都爬下来。
具体思路:
创建driver—–get网页—-找到并提取信息—–保存csv—-翻页—-get网页(开始循环)—-…—-没有“下一页”就结束,
用了while True,没用自我调用函数
嘟大海的微博:https://weibo.com/u/1623915527
办公室小野的微博:https://weibo.com/bgsxy
代码如下from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import csv
import os
import time
#只有这2个参数设置,想爬谁的微博数据就在这里改地址和目标csv名称就行
weibo_url = 'https://weibo.com/bgsxy?profile_ftype=1&is_all=1#_0'
csv_name = 'bgsxy_allweibo.csv'
def start_chrome():
print('开始创建浏览器')
driver = webdriver.Chrome(executable_path='C:/Users/lori/Desktop/python52project/chromedriver_win32/chromedriver.exe')
driver.start_client()
return driver
def get_web(url): #获取网页,并下拉到最底部
print('开始打开指定网页')
drive