sparklemotion / mechanize

Mechanize is a ruby library that makes automated web interaction easy.
https://www.rubydoc.info/gems/mechanize/
MIT License
4.39k stars 473 forks source link

More easily update Mechanize::AGENT_ALIASES #632

Closed takatea closed 7 months ago

takatea commented 7 months ago

This PR aims to facilitate the updating of Mechanize::AGENT_ALIASES. It can more easily update by generating output from examples/latest_user_agents.rb with the same structure as Mechanize::AGENT_ALIASES. In addition, I update User-Agent strings to represent modern browser version.

Execution Example

Below is the result of running the script examples/latest_user_agents.rb:

$ ruby examples/latest_user_agents.rb
fetch chrome UA...
sleeping... (1s)
fetch firefox UA...
sleeping... (1s)
fetch safari UA...
sleeping... (1s)
fetch edge UA...
sleeping... (1s)
{"Linux Firefox"=>"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/121.0",
 "Mac Firefox"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 14.2; rv:109.0) Gecko/20100101 Firefox/121.0",
 "Mac Safari"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 14_2_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15",
 "Windows Chrome"=>"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
 "Windows Edge"=>"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.2210.133",
 "Windows Firefox"=>"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0",
 "Android"=>"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.210 Mobile Safari/537.36",
 "iPhone"=>"Mozilla/5.0 (iPhone; CPU iPhone OS 17_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1",
 "iPad"=>"Mozilla/5.0 (iPad; CPU OS 17_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1"}
flavorjones commented 7 months ago

@takatea Thank you! Looks great.