|
| 1 | +--- |
| 2 | +title: Real User Agent |
| 3 | +description: >- |
| 4 | + getting started with Real UserAgent On Python. |
| 5 | +author: PyMmdrza |
| 6 | +date: 2025-01-29 17:11:10 +0800 |
| 7 | +categories: [Tutorial, Packages] |
| 8 | +tags: [real useragent, real user agent, real-useragent, getting started, install user agent, useragent, user agent, real] |
| 9 | +pin: true |
| 10 | +--- |
| 11 | + |
| 12 | +# Real User Agent Generator |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +```bash |
| 21 | +pip install real-useragent |
| 22 | +``` |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +Random User Agent on Any Device with any Browser Type (Recommended) |
| 27 | + |
| 28 | +```python |
| 29 | +import requests |
| 30 | +import real_useragent |
| 31 | + |
| 32 | +s = requests.Session() |
| 33 | +print(s.headers['User-Agent']) |
| 34 | + |
| 35 | +# Without a session |
| 36 | +resp = requests.get('https://httpbin.org/user-agent') |
| 37 | +print(resp.json()['user-agent']) |
| 38 | +``` |
| 39 | + |
| 40 | +- UserAgent |
| 41 | + |
| 42 | +```python |
| 43 | +from real_useragent import UserAgent |
| 44 | +ua = UserAgent() |
| 45 | +random_useragent = ua.random_useragent() |
| 46 | +``` |
| 47 | + |
| 48 | +### Random User Agent from Browser Name: |
| 49 | + |
| 50 | +```python |
| 51 | +from real_useragent import UserAgent |
| 52 | +ua = UserAgent() |
| 53 | +chrome_useragent = ua.chrome_useragent() |
| 54 | +firefox_useragent = ua.firefox_useragent() |
| 55 | +desktop_useragent = ua.desktop_useragent() |
| 56 | +mobile_useragent = ua.mobile_useragent() |
| 57 | +safari_useragent = ua.safari_useragent() |
| 58 | +``` |
| 59 | + |
| 60 | +### Random User Agent from Device Type and Browser : |
| 61 | + |
| 62 | +```python |
| 63 | +from real_useragent import UserAgent |
| 64 | +ua = UserAgent() |
| 65 | +mobile_firefox_ua = ua.get_useragent(mode="mobile", browser="firefox") |
| 66 | +desktop_chrome_ua = ua.get_useragent(mode="desktop", browser="chrome") |
| 67 | +``` |
| 68 | +### Random User Agent for Device Type (`mode`) |
| 69 | + |
| 70 | +```python |
| 71 | +from real_useragent import UserAgent |
| 72 | +ua = UserAgent() |
| 73 | +# mode : [desktop or mobile] |
| 74 | +desktop_useragent = ua.get_useragent(mode="desktop") |
| 75 | +mobile_useragent = ua.get_useragent(mode="mobile") |
| 76 | +``` |
| 77 | +- Desktop |
| 78 | + |
| 79 | +```python |
| 80 | +from real_useragent import UserAgent |
| 81 | +ua = UserAgent() |
| 82 | +desktop_firefox_useragent = ua.desktop_firefox_useragent() |
| 83 | +desktop_chrome_useragent = ua.desktop_chrome_useragent() |
| 84 | +desktop_linux_useragent = ua.desktop_linux_useragent() |
| 85 | +desktop_mac_useragent = ua.desktop_mac_useragent() |
| 86 | +``` |
| 87 | + |
| 88 | +- Mobile : |
| 89 | + |
| 90 | +```python |
| 91 | +from real_useragent import UserAgent |
| 92 | +ua = UserAgent() |
| 93 | +mobile_chrome_useragent = ua.mobile_chrome_useragent() |
| 94 | +mobile_firefox_useragent = ua.mobile_firefox_useragent() |
| 95 | +mobile_safari_useragent = ua.mobile_safari_useragent() |
| 96 | +``` |
| 97 | + |
| 98 | + |
| 99 | +User Agents are Randomized Per-Session or Per-Request. Individual HTTP requests without a session will each have a random User-Agent selected from the list in [desktop_useragent.txt](https://github.com/UserAgenter/real-useragent/blob/main/real-useragent/desktop_useragent.txt) or [mobile_useragent.txt](https://github.com/UserAgenter/real-useragent/blob/main/real-useragent/mobile_useragent.txt) all files automatically updated every 8 hours. |
| 100 | + |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +Programmer : [@Pymmdrza](https://github.com/Pymmdrza) |
| 105 | + |
| 106 | +Credit : [Mmdrza.Com](https://mmdrza.com) |
| 107 | + |
| 108 | +Medium : [MMDRZA](https://mdrza.medium.com 'medium page mmdrza') |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +# Donate |
| 113 | + |
| 114 | +Donate with Bitcoin: `1MMDRZA12xdBLD1P5AfEfvEMErp588vmF9` |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +[nodejs]: https://nodejs.org/ |
| 121 | +[real]: https://github.com/useragenter/real-useragent |
| 122 | +[pages-workflow-src]: https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow |
0 commit comments