Go fake-useragent to know

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Go fake-useragent to know

Some sites will be based on the different user-agent, jump to different (PC, M) site, but also according to the different version of the same hint, and so on, and user-agent change is the basic posture of reptiles

When using go to write a web crawler or need to simulate the browser header (user-agent), you will feel very troublesome, get the request header (ask Headers) user-agent still have to find, very cumbersome. I have had this problem before, so I have this project fake-useragent, to solve your pain point

Project Address: Https://github.com/EDDYCJY/fa ...

Support

    • All User-agent Random
    • Chrome
    • InternetExplorer (IE)
    • Firefox
    • Safari
    • Android
    • MacOSX
    • Ios
    • Linux
    • Iphone
    • Ipad
    • Computer
    • Mobile

Installation

$ go get github.com/EDDYCJY/fake-useragent

Usage

package mainimport ("Log" "Github.com/eddycjy/fake-useragent") func main () {//recommend using random: = Browser. Random () log. Printf ("Random:%s", random) Chrome: = browser. Chrome () log. Printf ("Chrome:%s", chrome) InternetExplorer: = browser. InternetExplorer () log. Printf ("IE:%s", InternetExplorer) Firefox: = browser. Firefox () log. Printf ("Firefox:%s", Firefox) Safari: = browser. Safari () log. Printf ("Safari:%s", Safari) android: = browser. Android () log. Printf ("Android:%s", Android) MacOSX: = browser. MacOSX () log. Printf ("MacOSX:%s", MacOSX) iOS: = browser. IOS () log. Printf ("ios:%s", ios) Linux: = browser. Linux () log. Printf ("Linux:%s", Linux) iphone: = Browser. IPhone () log. Printf ("iphone:%s", iphone) ipad: = browser. IPad () log. Printf ("ipad:%s", ipad) Computer: = Browser.computer () log. Printf ("Computer:%s", computer) Mobile: = browser. Mobile () log. Printf ("Mobile:%s", mobile)} 

Custom

You can adjust the maximum number of pages, the time interval, and the maximum time-out for fetching data sources. If it is not filled, the default value.

client := browser.Client{    MaxPage: 3,    Delay: 200 * time.Millisecond,    Timeout: 10 * time.Second,}cache := browser.Cache{}b := browser.NewBrowser(client, cache)random := b.Random()

Update the temporary file cache for the browser header

client := browser.Client{}cache := browser.Cache{    UpdateFile: true,}b := browser.NewBrowser(client, cache)

Finally, general usage is recommended, and default parameters can be used to meet everyday needs.

Output

random:mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) applewebkit/537.36 (khtml, like Gecko) chrome/63.0.3239.132 safari/537.36chrome:mozilla/5.0 (Wind OWS NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/60.0.3112.113 safari/537.36ie:mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; trident/5.0) firefox:mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) gecko/20100101 firefox/41.0safari:mozilla/5.0 (iPhone;  CPU iPhone os 11_2_5 like Mac os X applewebkit/604.5.6 (khtml, like Gecko) version/11.0 mobile/15d60 safari/604.1android: mozilla/5.0 (Linux; Android 6.0; Mya-l22 build/huaweimya-l22) applewebkit/537.36 (khtml, like Gecko) chrome/62.0.3202.84 Mobile safari/537.36macosx: mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) applewebkit/602.2.14 (khtml, like Gecko) version/10.0.1 safari/602.2.14ios:mozilla/5.0 (iPhone; C PU iPhone os 10_1 like Mac os X applewebkit/602.2.14 (khtml, like Gecko) version/10.0 mobile/14b72 Safari/602.1linux:moz illa/5.0 (X11; Linux x86_64; rv:42.0) gecko/20100101 firefox/42.0iphone:mozilla/5.0 (iPhone; CPU iPhone os 10_2 like Mac os X applewebkit/602.3.12 (khtml, like Gecko) version/10.0 mobile/14c92 Safari/602.1ipad:moz illa/5.0 (IPad; CPU os 5_0_1 like Mac os X applewebkit/534.46 (khtml, like Gecko) version/5.1 mobile/9a405 Safari/7534.48.3computer:mozi lla/5.0 (Windows NT 10.0; WOW64; rv:54.0) gecko/20100101 firefox/54.0mobile:mozilla/5.0 (Linux; Android 7.0; REDMI Note 4 build/nrd90m) applewebkit/537.36 (khtml, like Gecko) chrome/63.0.3239.111 Mobile safari/537.36

Attention

If you use it for the first time, Fake-useragent will collect the data and create a file in the Temp directory as the file cache, please wait a few seconds

At last

If you find any problem in the project, please submit PR or issue. Hope you can enjoy this project, the basic purpose or to solve the pain point, welcome star!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.