您好,登錄后才能下訂單哦!
一、安裝fake-useragent庫:
pip install fake-useragent
二、使用方法:
1、導入fake-useragent庫
from fake_useragent import UserAgent
2、實例化一個對象
ua = UserAgent()
3、隨機生成IE瀏覽器的UserAgent
ua.ie
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/4.0; GTB7.4; InfoPa
th.3; SV1; .NET CLR 3.1.76908; WOW64; en-US)'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .N
ET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; S
LCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba U
NTRUSTED/1.0'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; InfoPath.2; S
V1; .NET CLR 2.0.50727; WOW64)'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0'
4、隨機生成firefox瀏覽器的UserAgent
ua.firefox
u'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0'
ua.firefox
u'Mozilla/5.0 (Windows NT 5.0; rv:21.0) Gecko/20100101 Firefox/21.0'
ua.firefox
u'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'
ua.firefox
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0'
ua.firefox
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'
5、隨機生成chrome瀏覽器的UserAgent
ua.chrome
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/27.0.1453.93 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/35.0.1916.47 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40
.0.2214.93 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/41.0.2225.0 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like
Gecko) Chrome/24.0.1309.0 Safari/537.17'
6、隨機生成safari瀏覽器的UserAgent
ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 6.1; de-DE) AppleWebKit/533.20.25 (KHTML,
like Gecko) Version/5.0.3 Safari/533.19.4'
ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 6.1; ja-JP) AppleWebKit/533.20.25 (KHTML,
like Gecko) Version/5.0.3 Safari/533.19.4'
ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 6.1; sv-SE) AppleWebKit/533.19.4 (KHTML, l
ike Gecko) Version/5.0.3 Safari/533.19.4'
ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU) AppleWebKit/533.18.1 (KHTML, l
ike Gecko) Version/5.0.2 Safari/533.18.5'
7、隨機生成google瀏覽器的UserAgent
ua.google
u'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.
0.2224.3 Safari/537.36'
ua.google
u'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.
0.1453.93 Safari/537.36'
ua.google
u'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/41.0.2226.0 Safari/537.36'
ua.google
u'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.
0.3319.102 Safari/537.36'
8、隨機生成opera瀏覽器的UserAgent
ua.opera
u'Mozilla/5.0 (Windows NT 6.1; U; de; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 O
pera 11.01'
ua.opera
u'Opera/9.80 (Windows NT 6.1; Opera Tablet/15165; U; en) Presto/2.8.149 Version/
11.1'
ua.opera
u'Opera/9.80 (Windows NT 6.1; U; sv) Presto/2.7.62 Version/11.01'
ua.opera
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51'
ua.opera
u'Opera/9.80 (Windows NT 6.1; U; pl) Presto/2.7.62 Version/11.00'
9、隨機生成各種瀏覽器的UserAgent
ua.random
u'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/27.0.1453.93 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/30.0.1599.17 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/30.0.1599.17 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/41.0.2225.0 Safari/537.36'
ua.random
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/32.0.1664.3 Safari/537.36'
ua.random
u'Mozilla/5.0 (X11; CrOS i686 4319.74.0) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/29.0.1547.57 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko
) Chrome/32.0.1667.0 Safari/537.36'
ua.random
u'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0'
ua.random
u'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40
.0.2214.93 Safari/537.36'
ua.random
u'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2;
.NET CLR 2.0.50727; InfoPath.3; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR
3.0.30729; MS-RTC LM 8)'
三、查看fake-useragent版本
1、使用pip list命令查看fake-useragent版本
(scrapytest) F:\python-virtualenv\scrapytest\Scripts>pip list
attrs (17.3.0)
Automat (0.6.0)
certifi (2017.11.5)
cffi (1.11.2)
chardet (3.0.4)
constantly (15.1.0)
cryptography (2.1.3)
cssselect (1.0.1)
enum34 (1.1.6)
fake-useragent (0.1.8)
hyperlink (17.3.1)
idna (2.6)
訪問https://fake-useragent.herokuapp.com/browsers/0.1.8查看useragent庫
四、user-agent庫
https://fake-useragent.herokuapp.com/browsers/0.1.4
json格式顯示的,可以把內容復制到以下網址進行json視圖顯示
https://www.bejson.com/jsonviewernew/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。