Skip to content

kuro7766/Docker-Selenium-Firefox

Repository files navigation

BilibiliUp2

kuro7766 原 BilibiliUp (40⭐100 fork)残余的代码,可以在windows上运行

bilibili刷播放量,b站刷播放量,哔哩哔哩刷播放量

Windows 安装

需要下载firefox

安装对应的python pip环境

pip3 install chardet baidu-aip bs4 pdf2image markdown python-magic requests furl tendo pyperclip pillow selenium==3.14.0

修改bilibili_playcount_up.py里面的url,在第13行左右_driver.get('https://www.bilibili.com/video/你的bv号')

然后直接运行python bilibili_playcount_up.py。如果无法运行,需要找到适合的geckodriver版本。

正常情况下运行一次后停止,之后如需重复运行, 把56行左右的

    # while True:
    r = quick_firefox.run_sync(work=work, args=())

修改为

    while True:
        r = quick_firefox.run_sync(work=work, args=())

ubuntu installation

requirement:

ubuntu 20 or 18 . if you are using other versions of ubuntu , you have to find a compatible version of firefox and geckodriver

run this command:

apt-get install firefox=75.0+build3-0ubuntu1

and then install corresponding firefox gecko-driver to your env

wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
tar -xf geckodriver-v0.24.0-linux64.tar.gz
mv geckodriver /usr/local/bin

then install Selenium for python

pip3 install selenium==3.14.0

libs for ml.py if you want to include it:

pip3 install baidu-aip bs4 pdf2image markdown python-magic requests furl tendo pyperclip pillow

usage:

copy

quick_firefox.py,ml.py,selelib.py

and write your code like 0_google_screenshot.py

and then start coding

example:

import quick_firefox
import ml
ml.ensure_dir('screenshots')
links = quick_firefox.run_sync(work=callback_fun, args=())

then write your callback function like this,you have to leave two arguments

def work(_driver: WebDriver, args): 
    # do anything you want
    google = 'https://www.google.hk/search?q='
    _driver.get(google + 'python百度搜索提示api')
    
    # this javascript code may not work in the future 
    l = _driver.execute_script('''
    var elements = document.getElementsByClassName("yuRUbf");
    var r=[];
    for (var i = 0; i < elements.length; i++) {
        console.log(elements[i].children[0].href);
        r.push(''+elements[i].children[0].href);
    }
    return r;
    ''')

So you can manipulate the webdriver in reference from the selenium document

After this 'work' callback ,the firefox process will be killed automatically,so you don't need to call driver.quit() any more

Notice:

On Windows firefox will run with head as default,while on ubuntu it will run headless as default

About

Selenium×Firefox自动化爬虫模板

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages