99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁(yè)精彩閱讀App 端自動(dòng)化的最佳方案,完全解放雙手
App 端自動(dòng)化的最佳方案,完全解放雙手
2021-11-23
收藏

作者:星安果

來(lái)源:AirPython

App 端自動(dòng)化的最佳方案,完全解放雙手

1. 前言

大家好,我是安果!

之前寫過(guò)一篇文章,文中提出了一種方案,可以實(shí)現(xiàn)每天自動(dòng)給微信群群發(fā)新聞早報(bào)

如何利用 Python 爬蟲實(shí)現(xiàn)給微信群發(fā)新聞早報(bào)?(詳細(xì))

但是對(duì)于很多人來(lái)說(shuō),首先編寫一款 App 需要一定的移動(dòng)端開發(fā)經(jīng)驗(yàn),其次還需要另外編寫無(wú)障礙服務(wù)應(yīng)用,如此顯得有一定難度的

本篇文章將介紹另外一種方案,即:利用前面文章介紹的 AutoJS 來(lái)實(shí)現(xiàn)自動(dòng)給微信群發(fā)送新聞早報(bào)

2. 爬蟲及服務(wù)

為了演示方便,這里以百度熱搜為新聞早報(bào)數(shù)據(jù)源,

使用 Requests + BeautifulSoup 按熱度,爬取熱度最高的 15 條數(shù)據(jù)

import requests
from bs4 import BeautifulSoup
def baidu_top_tipic():
"""百度熱搜"""
requests_page = requests.get('http://top.baidu.com/buzz?b=1&c=513&fr=topbuzz_b42_c513')
soup = BeautifulSoup(requests_page.text, "lxml")
# 查詢
soup_text = soup.find_all("div", class_='c-single-text-ellipsis', text=True)
top_list = []
for index, text in enumerate(soup_text):
top_list.append((str(index + 1) + "、" + text.string.strip()))
# 取熱度最高的15條數(shù)據(jù)
return 'n'.join(top_list[:15])

然后,利用 FastAPI 編寫獲取新聞早報(bào)的 API,部署到云服務(wù)器上(這里以 CentOS 為例)

import uvicorn
from fastapi import FastAPI
from every_news import *
# pip3 install uvicorn
# pip3 install fastapi
# 實(shí)例化
app = FastAPI()
# 每日新聞
@app.get("/news")
async def rsc_api():
msg = get_news()
return {
"code": 200,
"msg": msg
}
if __name__ == '__main__':
uvicorn.run(app='news_api:app', host="0.0.0.0",
port=6789, reload=True, debug=True)

最后,運(yùn)行下面命令使服務(wù)在后臺(tái)運(yùn)行

# 命令行后臺(tái)運(yùn)行
# 日志目錄:/news_api.log
nohup python3 /xag/news_api.py > /news_api.log 2>&1 &

3. 自動(dòng)化發(fā)送群聊

在 VS Code 中編寫 AutoJS 腳本

首先,定義一個(gè)給群聊發(fā)送消息的方法

PS:使用 click() 坐標(biāo)執(zhí)行點(diǎn)擊操作僅適用于 Android 7.0+

//API調(diào)用獲取新聞數(shù)據(jù)
var url = "http://host:6789/news";
//發(fā)送群聊名稱
var group_name = "群聊名稱";
//發(fā)送信息給微信群
function send_wx_msg(group_name, send_msg) {
//如果休眠,喚醒設(shè)備
//注意:為了保證耗電低,設(shè)置睡眠(10s無(wú)操作)
device.wakeUpIfNeeded()
//打開微信
app.launch("com.tencent.mm");
text("微信").waitFor()
//點(diǎn)擊進(jìn)入到聊天界面
var chat_element_bounds = text(group_name).findOne().bounds();
//支持Android7.0+
click(
chat_element_bounds.centerX(), chat_element_bounds.centerY());

sleep(3000)
id("auj").className("EditText").findOne().setText(send_msg)
sleep(3000)
//發(fā)送消息
text("發(fā)送").click()
log("發(fā)送成功!")
//返回到手機(jī)桌面
back();
home();

然后,在主線程中啟動(dòng)一個(gè)新的線程,調(diào)用 API 接口,獲取數(shù)據(jù)后將數(shù)據(jù)發(fā)送出去

//線程
threads.start(function () {
//獲取新聞
http.get(url, {}, function (res, err) {
//錯(cuò)誤
if (err) {
log("抱歉!今天獲取新聞失敗。。。")
return;
}
log("今日新聞獲取成功!")
let html = res.body.string();
let msg = JSON.parse(html).msg;
send_wx_msg(group_name, msg)
});
})

接著,使用 VS Code 將源碼導(dǎo)入到手機(jī)設(shè)備上

最后,選中源文件 - 右鍵 - 更多 - 定時(shí)任務(wù),設(shè)置定時(shí)任務(wù)即可

App 端自動(dòng)化的最佳方案,完全解放雙手

4. 最后

如此,即可以實(shí)現(xiàn)每天早上給指定群發(fā)送新聞早報(bào)的功能

當(dāng)然,如果涉及多個(gè)群聊的發(fā)送,只需要使用 AutoJS 查詢多個(gè)目標(biāo)群聊對(duì)象 + 頁(yè)面滑動(dòng),遍歷進(jìn)行發(fā)送信息即可

另外,由于無(wú)障礙服務(wù)的不穩(wěn)定性,可以在設(shè)置中 AutoJS 應(yīng)用服務(wù)的優(yōu)先級(jí),保證程序的穩(wěn)定運(yùn)行

如果你覺(jué)得文章還不錯(cuò),請(qǐng)大家 點(diǎn)贊、分享、留言 下,因?yàn)檫@將是我持續(xù)輸出更多優(yōu)質(zhì)文章的最強(qiáng)動(dòng)力!

數(shù)據(jù)分析咨詢請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說(shuō)明請(qǐng)參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }