python3模块作为假用户代理的包装。
fakeua的Python项目详细描述
法克瓦
python3模块,作为伪用户代理的包装。
理由:
假用户代理包(https://github.com/hellysmile/fake-useragent) 有一个api,它很脆弱,太冗长,当你只想 可预测性和没有不必要头痛的工作。
安装
使用pip
安装pip3 install --user -U fakeua
用法
法克瓦也可以从贝壳中使用。
法克瓦-h
或导入其函数。
In [1]: import fakeua
# Update useragent DB in a json file (~/.fakeua_databrowsers.json)
In [2]: fakeua.update_useragent_db()
Out[2]: True
In [3]: fakeua.get_useragent_list()
Out[3]:
['Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0',
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0',
'Mozilla/5.0 (X11; Linux i586; rv:63.0) Gecko/20100101 Firefox/63.0',
'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0',
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.10; rv:62.0) Gecko/20100101 Firefox/62.0']
In [4]: fakeua.load_useragent_db()
Out[4]: ...
# It throws a dict containing the browsers scraped by fake-useragent.
In [5]: fakeua.get_random_ua()
Out[5]: 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0'