要整一个每天获取一批公众号发布的文章数据
大致流程如下

登录公众号后台—>创建图文—>点击超链接,即可选择公众号

浏览器F12可看到访问地址
https://mp.weixin.qq.com/cgi-bin/searchbiz?action=search_biz&begin=0&count=5&query=%E4%BA%BA%E6%B0%91%E6%97%A5%E6%8A%A5&token=1125413991&lang=zh_CN&f=json&ajax=1
里面的query参数就是你要查找的公众号名称
但是token长时间使用会失效,访问频率过高会被限制。
1.token获取
使用selenium通过chromedriver打开chrome浏览器每小时刷新页面保证能获取到最新的token和cookies信息保存到userMsg.txt文件中方便读取
#通过selenium打开Chrome浏览器用户扫码登录后页面定时刷新给token保活
#pip install selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import json
chrome_option = Options()
chrome_option.set_capability("goog:loggingPrefs", {
"performance": "ALL"})
driver = webdriver.Chrome(options=chrome_option)
driver.get('https://mp.weixin.qq.com')#用户登录后自己扫码
locator = (By.ID, 'js_index_menu')#判断用户是否扫码加载出了公众号菜单列表
WebDriverWait(driver, 120, 0.5).until(EC.presence_of_element_located(locator))#等待120秒,120秒内未扫码失效
print('login')
wait = WebDriverWait(driver, 10)
element = driver.find_element(By.ID, "js_index_menu")
def getNewToken(driver):
driver.refresh()#刷新页面
print('----------------------------打印cookies信息----------------------------------------')
# 获取当前页面的所有cookie
cookies = driver.get_cookies()
agent = driver.execute_script("return navigator.userAgent")
token = ''
cookieValue = ''
for cookie in cookies:
cookieValue = cookieValue+cookie[


6600

被折叠的 条评论
为什么被折叠?



