1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need a Python script to generate random mobile user agents

Discussion in 'General Scripting Chat' started by macdonjo3, Sep 21, 2015.

  1. macdonjo3

    macdonjo3 Jr. VIP Jr. VIP

    Joined:
    Nov 8, 2009
    Messages:
    5,652
    Likes Received:
    4,379
    Location:
    Toronto
    Home Page:
    Does anyone have a Python script that calculates random user agents of mobile users that they could share? I'd throw some cash your way if you'd like.
     
  2. fidodido

    fidodido Junior Member

    Joined:
    Aug 12, 2015
    Messages:
    113
    Likes Received:
    27
    Please, can you explain what you mean by "calculates random user agents of mobile users"
     
  3. macdonjo3

    macdonjo3 Jr. VIP Jr. VIP

    Joined:
    Nov 8, 2009
    Messages:
    5,652
    Likes Received:
    4,379
    Location:
    Toronto
    Home Page:
    I mean, it generates a random user agents based on reasonable market share.

    [​IMG]
     
  4. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    974
    Likes Received:
    680
    Occupation:
    Web/Bot Developer
    Here you go:

    Code:
    import random
    
    uagent_list = ['Android'] * 46 + ['iOS'] * 42 + ['Symbian'] * 3 + ['Java ME'] * 3 + ['Windows'] * 2 + ['Java ME'] * 1 + ['BlackBerry'] * 1 + ['Kindle'] * 1 + ['Other'] * 1
    
    random.choice(uagent_list)
    
    
     
    Last edited: Sep 21, 2015
  5. macdonjo3

    macdonjo3 Jr. VIP Jr. VIP

    Joined:
    Nov 8, 2009
    Messages:
    5,652
    Likes Received:
    4,379
    Location:
    Toronto
    Home Page:
    lol wise guy here. there are more factors to a user agent than the OS.
     
  6. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    974
    Likes Received:
    680
    Occupation:
    Web/Bot Developer
    Replace the OS name and percentages with your user agent list. The above is just an example of generating a weighted random number. Didn't think you needed to be spoon fed.

     
    Last edited: Sep 22, 2015
  7. McPatrick

    McPatrick Regular Member

    Joined:
    Feb 1, 2015
    Messages:
    244
    Likes Received:
    103
    Gender:
    Male
    Occupation:
    Problem-solver
    Location:
    London
    Home Page:
    Code:
    from fake_useragent import UserAgent
    This is a good start. They have a mobile module as well, so just reverse find it, I have seen mention about it on StackExchange last week, I cant find link though.
     
  8. MalthaelRico

    MalthaelRico Newbie

    Joined:
    Sep 11, 2015
    Messages:
    4
    Likes Received:
    0
    Hello TS, are you trying to make a mobile CPI bot software?
     
  9. macdonjo3

    macdonjo3 Jr. VIP Jr. VIP

    Joined:
    Nov 8, 2009
    Messages:
    5,652
    Likes Received:
    4,379
    Location:
    Toronto
    Home Page:
    Is this what you are referring to? https://pypi.python.org/pypi/fake-useragent
     
  10. skipsms

    skipsms Newbie

    Joined:
    Sep 24, 2015
    Messages:
    2
    Likes Received:
    0
    Did you get what you were looking for? I'll cook you up something if not.
     
  11. macdonjo3

    macdonjo3 Jr. VIP Jr. VIP

    Joined:
    Nov 8, 2009
    Messages:
    5,652
    Likes Received:
    4,379
    Location:
    Toronto
    Home Page:
    No, I have not yet.
     
  12. skipsms

    skipsms Newbie

    Joined:
    Sep 24, 2015
    Messages:
    2
    Likes Received:
    0
    Do you want the data based on a specific country, continent, or does it matter?
     
  13. ChanzGrande

    ChanzGrande Elite Member

    Joined:
    Feb 16, 2008
    Messages:
    2,487
    Likes Received:
    1,179
    Occupation:
    Accountant
    Location:
    Northern Woods Counting Money
    Your usage scenario here can clarify some possible best avenues of exploration, however I see Mr.Blue solution as possibly viable, and you could certainly substitute many more user-agents, or a random query to external resource from which to pull the UA.
     
  14. macdonjo3

    macdonjo3 Jr. VIP Jr. VIP

    Joined:
    Nov 8, 2009
    Messages:
    5,652
    Likes Received:
    4,379
    Location:
    Toronto
    Home Page:
    Doesn't matter

    macdonjo3
     
  15. duriangray

    duriangray Newbie

    Joined:
    Jul 22, 2014
    Messages:
    5
    Likes Received:
    0
    Location:
    California

    Lol I thought that was a joke....
    But it really exists.
     
  16. McPatrick

    McPatrick Regular Member

    Joined:
    Feb 1, 2015
    Messages:
    244
    Likes Received:
    103
    Gender:
    Male
    Occupation:
    Problem-solver
    Location:
    London
    Home Page: