Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More easily update Mechanize::AGENT_ALIASES #632

Merged

Conversation

takatea
Copy link
Contributor

@takatea takatea commented Jan 13, 2024

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"}

Mechanize::AGENT_ALIASES can easily update by using examples/latest_user_agents.rb

example:
```
require './examples/latest_user_agents'

agent = LatestUAFetcher.new
updated_user_agents = agent.user_agents.dup.delete_if do
  |key, value| Mechanize::AGENT_ALIASES[key] == value
end
pp updated_user_agents
```
@flavorjones
Copy link
Member

@takatea Thank you! Looks great.

@flavorjones flavorjones merged commit f75af0a into sparklemotion:main Jan 15, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants