开发者

How can I parse user-agent strings in Perl?

开发者 https://www.devze.com 2023-01-18 21:00 出处:网络
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:

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?


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消