czh的开发笔记 - 微信朋友圈 - 模拟操作

  • 这个爬虫效率极其低下,仅供学习参考使用
    • 朋友圈爬虫简介
    • 防喷
    • 个人要求
    • 环境配置(准备)
    • 环境配置(安装)
    • 工作原理
    • 源码自提
    • 源码展示与讲解
    • 后记

这个爬虫效率极其低下,仅供学习参考使用

朋友圈爬虫简介

模拟人工操作爬取朋友圈数据

防喷

  1. 这个代码写的确实很烂,我暂时也没有优化的动力

个人要求

  1. 需要会配置path
  2. 需要一定的python基础
  3. 需要有一定的前端调试经验
  4. 然后要有点耐心,这个环境配置确实需要一点时间,我这里也仅提供了win10+安卓的环境配置经验。

环境配置(准备)

  1. node+appium+adb 可以在下面的链接中下载

    1. node https://nodejs.org/zh-cn/
    2. adb https://www.androiddevtools.cn/ 这个是国内的安卓下载站,记得要找清楚是adb
    3. sdk Manager http://114.116.234.77:1234/android-sdk_r24.4.1-windows.zip 这个是放在我的服务器上的,你也可以自己找
    4. appium http://appium.io/ 这个直接去官网上下载就好
  2. python环境 建议直接使用Anaconda https://www.anaconda.com/
  3. 编辑器啥的自己搞定(vsCode强烈安利)

环境配置(安装)

  1. 安装node(双击安装包即可)

    1. 安装结束后记得修改源(如下)
npm config set registry https://registry.npm.taobao.org
  1. 安装appium和adb

    1. 安装完成后记得配置path,添加一条指向adb文件夹内的路径
  2. 安装sdkManager(双击安装即可)
  3. python环境(我的源码用的是python3,记得注意版本)

工作原理

原理很简单,如下

#mermaid-svg-szoY1Z77aVEnsHoF .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-szoY1Z77aVEnsHoF .label text{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .node rect,#mermaid-svg-szoY1Z77aVEnsHoF .node circle,#mermaid-svg-szoY1Z77aVEnsHoF .node ellipse,#mermaid-svg-szoY1Z77aVEnsHoF .node polygon,#mermaid-svg-szoY1Z77aVEnsHoF .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-szoY1Z77aVEnsHoF .node .label{text-align:center;fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .node.clickable{cursor:pointer}#mermaid-svg-szoY1Z77aVEnsHoF .arrowheadPath{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-szoY1Z77aVEnsHoF .flowchart-link{stroke:#333;fill:none}#mermaid-svg-szoY1Z77aVEnsHoF .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-szoY1Z77aVEnsHoF .edgeLabel rect{opacity:0.9}#mermaid-svg-szoY1Z77aVEnsHoF .edgeLabel span{color:#333}#mermaid-svg-szoY1Z77aVEnsHoF .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-szoY1Z77aVEnsHoF .cluster text{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-szoY1Z77aVEnsHoF .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-szoY1Z77aVEnsHoF text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-szoY1Z77aVEnsHoF .actor-line{stroke:grey}#mermaid-svg-szoY1Z77aVEnsHoF .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-szoY1Z77aVEnsHoF .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-szoY1Z77aVEnsHoF #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-szoY1Z77aVEnsHoF .sequenceNumber{fill:#fff}#mermaid-svg-szoY1Z77aVEnsHoF #sequencenumber{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF #crosshead path{fill:#333;stroke:#333}#mermaid-svg-szoY1Z77aVEnsHoF .messageText{fill:#333;stroke:#333}#mermaid-svg-szoY1Z77aVEnsHoF .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-szoY1Z77aVEnsHoF .labelText,#mermaid-svg-szoY1Z77aVEnsHoF .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-szoY1Z77aVEnsHoF .loopText,#mermaid-svg-szoY1Z77aVEnsHoF .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-szoY1Z77aVEnsHoF .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-szoY1Z77aVEnsHoF .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-szoY1Z77aVEnsHoF .noteText,#mermaid-svg-szoY1Z77aVEnsHoF .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-szoY1Z77aVEnsHoF .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-szoY1Z77aVEnsHoF .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-szoY1Z77aVEnsHoF .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-szoY1Z77aVEnsHoF .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .section{stroke:none;opacity:0.2}#mermaid-svg-szoY1Z77aVEnsHoF .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-szoY1Z77aVEnsHoF .section2{fill:#fff400}#mermaid-svg-szoY1Z77aVEnsHoF .section1,#mermaid-svg-szoY1Z77aVEnsHoF .section3{fill:#fff;opacity:0.2}#mermaid-svg-szoY1Z77aVEnsHoF .sectionTitle0{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .sectionTitle1{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .sectionTitle2{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .sectionTitle3{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-szoY1Z77aVEnsHoF .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .grid path{stroke-width:0}#mermaid-svg-szoY1Z77aVEnsHoF .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-szoY1Z77aVEnsHoF .task{stroke-width:2}#mermaid-svg-szoY1Z77aVEnsHoF .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .taskText:not([font-size]){font-size:11px}#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-szoY1Z77aVEnsHoF .task.clickable{cursor:pointer}#mermaid-svg-szoY1Z77aVEnsHoF .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-szoY1Z77aVEnsHoF .taskText0,#mermaid-svg-szoY1Z77aVEnsHoF .taskText1,#mermaid-svg-szoY1Z77aVEnsHoF .taskText2,#mermaid-svg-szoY1Z77aVEnsHoF .taskText3{fill:#fff}#mermaid-svg-szoY1Z77aVEnsHoF .task0,#mermaid-svg-szoY1Z77aVEnsHoF .task1,#mermaid-svg-szoY1Z77aVEnsHoF .task2,#mermaid-svg-szoY1Z77aVEnsHoF .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutside0,#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutside2{fill:#000}#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutside1,#mermaid-svg-szoY1Z77aVEnsHoF .taskTextOutside3{fill:#000}#mermaid-svg-szoY1Z77aVEnsHoF .active0,#mermaid-svg-szoY1Z77aVEnsHoF .active1,#mermaid-svg-szoY1Z77aVEnsHoF .active2,#mermaid-svg-szoY1Z77aVEnsHoF .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-szoY1Z77aVEnsHoF .activeText0,#mermaid-svg-szoY1Z77aVEnsHoF .activeText1,#mermaid-svg-szoY1Z77aVEnsHoF .activeText2,#mermaid-svg-szoY1Z77aVEnsHoF .activeText3{fill:#000 !important}#mermaid-svg-szoY1Z77aVEnsHoF .done0,#mermaid-svg-szoY1Z77aVEnsHoF .done1,#mermaid-svg-szoY1Z77aVEnsHoF .done2,#mermaid-svg-szoY1Z77aVEnsHoF .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-szoY1Z77aVEnsHoF .doneText0,#mermaid-svg-szoY1Z77aVEnsHoF .doneText1,#mermaid-svg-szoY1Z77aVEnsHoF .doneText2,#mermaid-svg-szoY1Z77aVEnsHoF .doneText3{fill:#000 !important}#mermaid-svg-szoY1Z77aVEnsHoF .crit0,#mermaid-svg-szoY1Z77aVEnsHoF .crit1,#mermaid-svg-szoY1Z77aVEnsHoF .crit2,#mermaid-svg-szoY1Z77aVEnsHoF .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-szoY1Z77aVEnsHoF .activeCrit0,#mermaid-svg-szoY1Z77aVEnsHoF .activeCrit1,#mermaid-svg-szoY1Z77aVEnsHoF .activeCrit2,#mermaid-svg-szoY1Z77aVEnsHoF .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-szoY1Z77aVEnsHoF .doneCrit0,#mermaid-svg-szoY1Z77aVEnsHoF .doneCrit1,#mermaid-svg-szoY1Z77aVEnsHoF .doneCrit2,#mermaid-svg-szoY1Z77aVEnsHoF .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-szoY1Z77aVEnsHoF .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-szoY1Z77aVEnsHoF .milestoneText{font-style:italic}#mermaid-svg-szoY1Z77aVEnsHoF .doneCritText0,#mermaid-svg-szoY1Z77aVEnsHoF .doneCritText1,#mermaid-svg-szoY1Z77aVEnsHoF .doneCritText2,#mermaid-svg-szoY1Z77aVEnsHoF .doneCritText3{fill:#000 !important}#mermaid-svg-szoY1Z77aVEnsHoF .activeCritText0,#mermaid-svg-szoY1Z77aVEnsHoF .activeCritText1,#mermaid-svg-szoY1Z77aVEnsHoF .activeCritText2,#mermaid-svg-szoY1Z77aVEnsHoF .activeCritText3{fill:#000 !important}#mermaid-svg-szoY1Z77aVEnsHoF .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-szoY1Z77aVEnsHoF g.classGroup text .title{font-weight:bolder}#mermaid-svg-szoY1Z77aVEnsHoF g.clickable{cursor:pointer}#mermaid-svg-szoY1Z77aVEnsHoF g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-szoY1Z77aVEnsHoF g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-szoY1Z77aVEnsHoF .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-szoY1Z77aVEnsHoF .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-szoY1Z77aVEnsHoF .dashed-line{stroke-dasharray:3}#mermaid-svg-szoY1Z77aVEnsHoF #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF .commit-id,#mermaid-svg-szoY1Z77aVEnsHoF .commit-msg,#mermaid-svg-szoY1Z77aVEnsHoF .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-szoY1Z77aVEnsHoF g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-szoY1Z77aVEnsHoF g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-szoY1Z77aVEnsHoF g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-szoY1Z77aVEnsHoF .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-szoY1Z77aVEnsHoF .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-szoY1Z77aVEnsHoF .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-szoY1Z77aVEnsHoF .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-szoY1Z77aVEnsHoF .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-szoY1Z77aVEnsHoF .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-szoY1Z77aVEnsHoF .edgeLabel text{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-szoY1Z77aVEnsHoF .node circle.state-start{fill:black;stroke:black}#mermaid-svg-szoY1Z77aVEnsHoF .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-szoY1Z77aVEnsHoF #statediagram-barbEnd{fill:#9370db}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-state .divider{stroke:#9370db}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-szoY1Z77aVEnsHoF .note-edge{stroke-dasharray:5}#mermaid-svg-szoY1Z77aVEnsHoF .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-szoY1Z77aVEnsHoF .error-icon{fill:#522}#mermaid-svg-szoY1Z77aVEnsHoF .error-text{fill:#522;stroke:#522}#mermaid-svg-szoY1Z77aVEnsHoF .edge-thickness-normal{stroke-width:2px}#mermaid-svg-szoY1Z77aVEnsHoF .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-szoY1Z77aVEnsHoF .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-szoY1Z77aVEnsHoF .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-szoY1Z77aVEnsHoF .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-szoY1Z77aVEnsHoF .marker{fill:#333}#mermaid-svg-szoY1Z77aVEnsHoF .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-szoY1Z77aVEnsHoF {color: rgba(0, 0, 0, 0.75);font: ;}

通过端口发送
转译指令
python脚本
appium
真机

源码自提

https://github.com/czhmisaka/wxPYQspider_fake

源码展示与讲解

  1. 在桌面准备一个 nameList.txt(如下)
  2. 用usb线(需要稳定性较好,最好是type-C的全功能线)链接手机
    1. 手机需要打开开发者模式以及usb调试
  3. 在终端中输入abd devices 检查设备是否链接成功
  4. 运行python脚本
    1. 此时被操作手机中会出现一个新的应用(Appium setting),需要给这个应用最高权限,以及避免被系统自动关闭(内存优化,后台搞耗电,自启动管理等设置需要调整)
  5. 重新运行脚本

from appium import webdriver
import time
import re
import sys
import os
from appium.webdriver.common.touch_action import TouchAction
import json
import numpy as np
import pathlib
import sys
from cv2 import cv2 as cvdriver = {}def imgFormat(path):return Truedef cv_imread(filePath):cv_img=cv.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)return cv_imgdef change(path):path_str = pathalpha = 0.02img = cv_imread(str(path))if img is None: return img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) / 255h_mid = img_gray.shape[0] // 2w_mid = img_gray.shape[1] // 2u = h_midwhile u >= 0 and np.mean(img_gray[u]) > alpha: u -= 1b = h_midwhile b < img_gray.shape[0] and np.mean(img_gray[b]) > alpha: b += 1l = w_midwhile l >= 0 and np.mean(img_gray[:, l]) > alpha : l -= 1r = w_midwhile r < img_gray.shape[1] and np.mean(img_gray[:, r]) > alpha: r += 1try:asd = 'a_'pathList = path.split('/')pathName = ''for x in range(len(pathList)):if x==0:pathName = pathList[x]elif x!=len(pathList):pathName = pathName+'/'+pathList[x]else:pathName = pathName+'/'+ 'a_'+pathList[x] + '.png'print(pathName)cv.imencode('.png', img[u + 1:b - 1, l + 1:r - 1])[1].tofile(f'{pathName}')except:print('e')# 获取桌面路径
def getDesktopPath():return os.path.join(os.path.expanduser('~'),"Desktop")+'/'# 创建文件夹
def mkdirFile(path):try:if not os.path.exists(path):os.makedirs(path)return Trueelse:return 'createFail'except:return 'existsFail'# 创建json文件
def writeJson(path,data):with open(path+'/1.json','w') as fileObj:json.dump(data,fileObj)def writeJson2(path,data):with open(path,'w') as fileObj:json.dump(data,fileObj)# 截屏并保存
def SaveScreenShot(path,name=''):try:if name == '':for x in range(10):testPath = path+'/'+str(x)+'.png'print(testPath)if checkFile(testPath):driver.get_screenshot_as_file(testPath)change(testPath)return xreturn "max"else:for x in range(10):testPath = path+'/'+str(name)+str(x)+'.png'if checkFile(testPath):driver.get_screenshot_as_file(testPath)change(testPath)return xreturn "max"except:print('FUCK!!!!!!!!!!!!!!')# 检查文件存在
def checkFile(path):if os.path.exists(path):return Falseelse:return True# 列表展示
def printList(lists):for x in lists:print(x)#进入昵称为name的好友的朋友圈的点击逻辑
def enter_pengyouquan(name):driver.find_element_by_id('com.tencent.mm:id/f8y').click()  #点击搜索图标# driver.find_element_by_id('com.tencent.mm:id/cn_').click()time.sleep(2)driver.find_element_by_id('com.tencent.mm:id/bhn').send_keys(name)  #输入搜索文字time.sleep(2)driver.find_element_by_id('com.tencent.mm:id/tm').click()  #点击第一个搜索结果time.sleep(1)driver.find_element_by_id('com.tencent.mm:id/cj').click()  #点击聊天界面右上角三个小点time.sleep(1)driver.find_element_by_id('com.tencent.mm:id/f3y').click() #点击头像time.sleep(1)driver.find_element_by_id('com.tencent.mm:id/coy').click() #点击朋友圈time.sleep(1)#上拉方法
def swipe_up(distance, time):  #distance为滑动距离,time为滑动时间width = 1080height = 2150  # width和height根据不同手机而定driver.swipe(1 / 2 * width, 9 / 10 * height, 1 / 2 * width, (9 / 10 - distance) * height, time)#获取当前朋友圈界面的文字
def get_onepage():eleLst = get_onepage_elementlist()pagetext = []for e in eleLst:try:pagetext.append(e.get_attribute('text'))except:passreturn pagetext#获取当前朋友圈界面的相关元素
def get_onepage_elementlist():# pict_list = driver.find_element_by_id('com.tencent.mm:id/cpu')pict_list = driver.find_elements_by_id('com.tencent.mm:id/fnn')  #带图朋友圈配文和视频朋友圈配文link_list = driver.find_elements_by_id('com.tencent.mm:id/kt')  #链接朋友圈配文和纯文字朋友圈elementlist = pict_listpic_list = driver.find_elements_by_xpath('//android.view.View[@content-desc="图片"]')printList(pic_list)return elementlist#获取往前倒推year_count年到现在的所有朋友圈
def get_pages(year_count):pagestext = []# current_year = driver.find_element_by_id("com.tencent.mm:id/ekg").get_attribute("text") #获得当前年份while True:try:end_year = str(int(current_year[0:4]) - year_count) + "年"y = driver.find_element_by_id("com.tencent.mm:id/ekg").get_attribute("text")   #在页面中寻找显示年份的元素,没找到就会报错,继续上拉if y == end_year:   #到达结束年份breakelse:  #未到达结束年份,继续上拉pagetext=get_onepage()for t in pagetext:if t not in pagestext:pagestext.append(t)swipe_up(1 / 2, 2000)except:pagetext = get_onepage()for t in pagetext:if t not in pagestext:pagestext.append(t)swipe_up(1 / 2, 2000)pagetext = get_onepage()for t in pagetext:if t not in pagestext:pagestext.append(t)while True:try:driver.find_element_by_id("com.tencent.mm:id/ekg")swipe_up(1/12,500)except:break#删除最后一页多获取的朋友圈文本lastPage=get_onepage()for t in lastPage:if t in pagestext:pagestext.remove(t)return pagestextdef store_PYQText(PYQ_list,store_path):  #将朋友圈文本存储到指定路径f = open(store_path, 'w', encoding='utf-8')for text in PYQ_list:f.write(text + '\n\n')f.close()#去除表情文本
def remove_icondesc(list, storepath):f = open(storepath, 'w', encoding='utf-8')patten = re.compile('\w+(?![\u4e00-\u9fa5]*])')  #匹配除表情文本外的所有文本for s in list:splitted_sentences = re.findall(patten, s)for p in splitted_sentences:f.write(p + '\n')f.close()def enter_pengyouquan_all():driver.find_element_by_id('com.tencent.mm:id/cnh').click()  #点击搜索图标time.sleep(2)def tap(x,y,times=100):driver.tap([(x,y)],times)def getScreenSize():size = driver.get_window_size()return sizedef X(x):return x/100*size['width']def Y(y):return y/100*size['height']class Point:pass
def swipe_down(fromP={},toP={},times=3000):if fromP:if toP:return driver.swipe(fromP.x, fromP.y, toP.x,toP.y,times)return driver.swipe(X(70),Y(80),X(30),Y(20),times)def swipe_up2():return driver.swipe(X(70),Y(20),X(30),Y(80),1000)def swipe_r2l():return driver.swipe(X(90),Y(50),X(10),Y(50),400)def toPYQ():tap(676,2162)time.sleep(3)tap(454,296)time.sleep(3)    def kick(times=0.5):time.sleep(times)def main_saveByName(nameList):size = {'width':1,'height':1}deviceConfig = {'platformName':'Android'}size = {'width':1,'height':1}
desired_caps = {'platformName': 'Android','deviceName': '37KNW18710001152','platformVersion': '9','appPackage': 'com.tencent.mm',  # apk包名'appActivity': 'com.tencent.mm.ui.LauncherUI',  # apk的launcherActivity'noReset': 'True',  # 每次运行脚本不用重复输入密码启动微信'unicodeKeyboard': 'True',  # 使用unicodeKeyboard的编码方式来发送字符串'resetKeyboard': 'True'  # 将键盘给隐藏起来
}asd = {"platformName": "Android","platformVersion": "10","deviceName": "HA19RRAZ","appPackage": "com.tencent.mm","appActivity": "com.tencent.mm.ui.LauncherUI","noReset": "true","automationName":"uiautomator2"
}
driver = {}
pyq = {}nameList = []
fr = open(getDesktopPath()+'nameList.txt', encoding='utf-8',errors='ignore')
nameList = fr.read().split('\n')
num = 0# 防止文件夹名称重复
preName = ''
preNum = 0
# 防止文件夹名称重复for xx in nameList:try:if xx == "":continuex = str(xx)list = []print(nameList,x,'次数',str(num))try:driver.quit()except:print('开始')driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', asd)size = getScreenSize()kick(5)enter_pengyouquan(x) kick(5)# toPYQ()timeNow = time.strftime("%Y-%m-%d", time.localtime())namePath = getDesktopPath()+'\\test\\'+str(x)+str(timeNow)mkdirFile(namePath)for x in range(10):swipe_down('','',1000)kick(1)for x in range(11):swipe_up2()kick(1)try:comeIn = driver.find_element_by_id('com.tencent.mm:id/cpu')comeIn.click()kick()except:try:comeIn = driver.find_element_by_id('com.tencent.mm:id/cpu')comeIn.click()kick()except:print('clickFail')# try:#     leak = driver.find_element_by_id('com.tencent.mm:id/g95')#     leak.click()#     kick()   # except:#     try:#         leak = driver.find_element_by_id('com.tencent.mm:id/g95')#         leak.click()#         kick()   #     except:#         print('fuck2')for y in range(10000):tap(X(50),Y(50),800)time.sleep(1)try:save = driver.find_elements_by_id('com.tencent.mm:id/gam')except:print('保存失败')else:for c in save:if c.text == '保存图片' or c.text == '保存视频':num = num + 1print('当前轮数:'+str(y)+'    已保存图片数量:'+str(num))c.click()kick()breakkick()kick(2)name = str(y)+'_'try:contextObj = driver.find_element_by_class_name('android.widget.TextView')name = contextObj.text.replace('\n', '').replace('\r', '').strip()name = name.replace('\\','')timeObj = driver.find_element_by_id('android:id/text1')timesss = timeObj.texttimesss = timesss.replace(':','').strip()print(timesss)except:print('context fail')if name in list:preNamemkdirFile(namePath+'/'+timesss+name)    kick()maxNum = SaveScreenShot(namePath+'/'+timesss+name)if maxNum == 'max':breakkick()try:swipe_r2l()except:kick()try:swipe_r2l()except:print('fail')except:nameList.append(xx)

后记

这个博文其实也没有讲的很细,之后再补充

czh的开发笔记 - 微信朋友圈 - 模拟操作相关推荐

  1. 淦!女票问我能不能开发一个微信朋友圈、微博?

    点击上方"芋道源码",选择"设为星标" 管她前浪,还是后浪? 能浪的浪,才是好浪! 每天 8:55 更新文章,每天掉亿点点头发... 源码精品专栏 原创 | J ...

  2. android开发--仿微信朋友圈界面

    话不多说,先来看两张效果图 看图片效果还凑合,就是"朋友圈"三个字和头像的动画过渡效果和微信朋友圈的实际效果还是有点差距,可以的话以后慢慢再优化吧,这里贴出相关的代码,可能部分代码 ...

  3. 农村信息综合展示平台(微信网页)项目开发笔记三——朋友圈开发遇到的问题

    本篇记录在朋友圈功能页面中实现图片点击放大查看的功能,遇到了的问题 本系统是使用Vux库因此,为实现查看图片的功能就使用了Vux自带的Previewer,如何使用在这里就不多说,之间查看Vux文档. ...

  4. node拉取微信权限,实现自定义分享微信朋友圈等操作

    最近做一个应用需要实现自定义分享朋友圈的文字和图片,然后找了很多文章,总结趴坑如下,或许对你很有帮助,我看别人写的都是乱七八糟的,浪费我好多时间,所以决定自己写一个,保证拿过去直接用 node实现代码 ...

  5. autojs开发的微信朋友圈点赞自动化脚本源码,安卓免root运行

    说明 本文提供的代码仅供参考.不建议用于生产环境. 可能有些地方在最新版本的Auto.js上面需要做修改,才能运行. Auto.js简介 Auto.js是利用安卓系统的"辅助功能" ...

  6. 微信朋友圈“文字发”操作技巧,轻松实现不带图发布

    微信朋友圈"文字"操作技巧,轻松实现不带图发布 微信朋友圈作为一款非常受欢迎的社交软件,不仅可以让我们方便地分享照片.视频等内容,还可以通过文字来表达自己的想法和感受.但是,有时候 ...

  7. html微信朋友圈demo,Vue.js实现模拟微信朋友圈开发demo

    我用Vue.js实现微信朋友圈的一些功能,实现展示朋友圈,评论,点赞. 先构造一个vue的实例,对会更改的数据进行双向绑定, 我用JSON伪造模版数据,先实现显示朋友圈的效果,使用v-for方法去循环 ...

  8. 后台模拟页面登陆_微信直播小程序后台,微信朋友圈可直达小程序直播了

    独家了解到,微信广告正在测试直播模式,可以帮助商家将直播小程序置于多个广告流量级别,如朋友圈,公众账号和小程序. 这也意味着微信生态系统中的商家不仅可以通过小节目现场直播来运营私有域流量,而且可以利用 ...

  9. IM开发技术学习:揭秘微信朋友圈这种信息推流背后的系统设计

    本文由徐宁发表于腾讯大讲堂,原题"程序员如何把你关注的内容推送到你眼前?揭秘信息流推荐背后的系统设计",有改动和修订. 1.引言 信息推流(以下简称"Feed流" ...

最新文章

  1. 安卓应用如何引用动态库
  2. 树莓派 修改config.txt配置文件
  3. redis 安装后不能使用
  4. 毕业一年多被裁,没有计算机文凭,我在两个月内搞定4份Offer,且收入翻倍
  5. Linux应用程序和驱动程序如何完成交互,应用程序和驱动的简易交互方式的实现...
  6. Java—Object类及自定义克隆详解
  7. 用winformz时间格式不正确_煮八爪鱼,有人用冷水,有人用开水,大厨:都不对,教你正确做法...
  8. Flutter从入门到进阶
  9. UE4分支的Git Flow
  10. 蓝桥杯2015年第六届javaB组省赛第一题-三角形面积
  11. H264--H264解码--5
  12. IAR在写结构体时不提示_U盘被写保护了以后怎么办?
  13. 微信记录删了,怎么恢复找回来?5种攻略推荐
  14. CSS字体样式属性调试
  15. 标识符的命名规则及命名规范
  16. Pika的设计及实现
  17. 如何给PDF文件添加页码
  18. 电脑桌面便签怎么修改便签字体颜色?
  19. modprobe命令加载驱动问题?
  20. Maven(一):什么是Maven?

热门文章

  1. siri接入易微联_拓展生态链接新航道 酷宅科技易微联从本质出发
  2. 爬取超星考试题目_如何使用网页的源代码分析找到超星线上考试的答案
  3. mysql myisam表_mysql优化之MyISAM表锁
  4. BAT 再无百度!互联网十强还会有百度吗?
  5. oracle 10046事件详解
  6. B - Bin Packing Problem (线段树+multiset)
  7. MyEclipse+Tomcat配置详解
  8. gdbm.h: No such file or directory
  9. Vulnhub-vulncms
  10. PCL 惯性矩和偏心率