6

I need to parse the user-agents in HTTP-headers from a text file so as to determine the browser, the version, the OS and possibly the device. so few examples of those lines are:

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Update a; AOL 6.0; Windows 98)

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Crazy Browser 2.0.0 Beta 1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)

User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-de) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10

User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 95) Opera 6.01  [en]

Due to the sheer variety of these strings I figured it would be a better idea to utilize a proven and dependable parser that someone has made available. I did find a few in PHP or java but don't seem to find one for Perl.

Can someone tell me about any such module?

3 Answers 3

16

You might be looking for the HTTP::BrowserDetect module.

Sign up to request clarification or add additional context in comments.

Comments

1

Whenever you need something in Perl, try CPAN Search. Searching for user agent shows in just the first page of results several modules that you might use.

Comments

1

I did a review of all Perl CPAN modules for parsing the User-Agent string:

http://blogs.perl.org/users/neilb/2011/10/cpan-modules-for-parsing-user-agent-strings.html

There are a number of modules which are actively maintained. Best coverage of regular web browsers is currently (Jan 2012) provided by HTML::ParseBrowser, which I'm maintaining.

Neil

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.