Skip to content

Commit

Permalink
Randomize userAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
timolins committed Mar 7, 2018
1 parent 69dc42a commit 3af4c88
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ const fs = require('fs')
const request = require('request-promise-native')
const { Cookie } = require('tough-cookie')
const isUrl = require('is-url')
const useragentFromSeed = require('useragent-from-seed')

const baseUrl = 'https://www.instagram.com'
const userAgent =
'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'

class Instagram {
constructor({ username, password, cookies }, { language, proxy } = {}) {
Expand All @@ -26,6 +25,8 @@ class Instagram {
csrftoken = cookies.find(({ key }) => key === 'csrftoken').value
}

const userAgent = useragentFromSeed(username)

this.request = request.defaults({
baseUrl,
headers: {
Expand Down
82 changes: 80 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"is-url": "^1.2.2",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"tough-cookie": "^2.3.3"
"tough-cookie": "^2.3.3",
"useragent-from-seed": "^1.0.0"
},
"devDependencies": {
"ava": "^0.24.0",
Expand Down

0 comments on commit 3af4c88

Please sign in to comment.