序文
スクリプトの主なロジックは、タイマーとマルチスレッドを使用して、自動ビデオ表示のループ実行を実装することです。loop_monitor() 関数は、タイマー オブジェクトを作成して views() 関数を呼び出し、5 秒ごとに views() 関数を実行します。
#views() 関数は、最後の実行からの時間が 1000 秒を超えているかどうかを判断します。超えた場合は、
view_int() 関数を呼び出すタイマー オブジェクトが作成され、10 分間スリープします。view_int() 関数は 5 つのスレッドを作成し、各スレッドは Auto_Like_Your_Video() 関数を呼び出して自動ブラッシング操作を実行します。
Auto_Like_Your_Video() 関数では、ChromeOptions を設定して、ユーザー エージェントの設定、プロキシの使用などのブラウザ オプションを構成します。
次に、webdriver.Chrome オブジェクトを作成し、get() メソッドを呼び出して指定された Web ページを開き、一連の操作を実行して、最後にブラウザを終了します。stop()関数がTrueを返したと判定された場合、ループを抜けて再生音量を上げる動作を停止します。
1. 準備
proxypool は、無料のオープンソースのプロキシ プールです。インストールの詳細については説明しませんが、午後中ずっとこの作業に取り組みましたが、とてもひどいものでした。
2. 利用手順
1. ライブラリをインポートする
コードは次のとおりです(例)。
import random
from selenium import webdriver
from threading import Timer
import time
import requests
import threading
import asyncio
from bilibili_api import video
2.コアコード
コードは次のとおりです(例)。
def view_int():
print('初始化成功')
global state
do1 = threading.Thread(target=Auto_Like_Your_Video, args=(get_proxy().get("proxy"), state,))
do2 = threading.Thread(target=Auto_Like_Your_Video, args=(get_proxy().get("proxy"), state,))
do3 = threading.Thread(target=Auto_Like_Your_Video, args=(get_proxy().get("proxy"), state,))
do4 = threading.Thread(target=Auto_Like_Your_Video, args=(get_proxy().get("proxy"), state,))
do5 = threading.Thread(target=Auto_Like_Your_Video, args=(get_proxy().get("proxy"), state,))
print('线程打开')
do1.start()
do2.start()
do3.start()
do4.start()
do5.start()
time.sleep(2)
state = True
print('线程关闭')
do1.join()
do2.join()
do3.join()
do4.join()
do5.join()
state = False
ここで使用される URL ネットワークによって要求されたデータ。
def Auto_Like_Your_Video(url,stop):
print(stop)
global b_time
try:
USER_AGENT = [
'Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.229 Version/11.62',
'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 Version/11.52',
'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20130331 Firefox/21.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0',
]
ChromeOptions = webdriver.ChromeOptions()
ua = random.choice(USER_AGENT)
ChromeOptions.add_argument('--user-agent=%s' % ua)
ChromeOptions.add_argument("--proxy-server=" + "http://" + str(url))
# desired_capabilities = DesiredCapabilities.CHROME
# desired_capabilities["pageLoadStrategy"] = "none"
driver = webdriver.Chrome(
r'xxxxx\chromedriver.exe',
options=ChromeOptions)
driver.get('https://www.bilibili.com/video/xxxx')
if driver.title == 'www.bilibili.com':
print('页面访问失败')
driver.close()
time.sleep(b_time / random.randint(1, 4))
driver.close()
if stop:
print(stop)
except:
pass
要約する
未解決の問題を Linux サーバーに展開できません。調査した結果、Web ドライバーが正常に有効になっていないようです。誰かが助けてくれることを願っています。