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

support persistent variables (e.g. access tokens) #32

Open
andykais opened this issue Sep 7, 2019 · 0 comments
Open

support persistent variables (e.g. access tokens) #32

andykais opened this issue Sep 7, 2019 · 0 comments

Comments

@andykais
Copy link
Owner

andykais commented Sep 7, 2019

we have a need to get a variable once and reuse it throughout the config. There are a few options:

we just store the last value out of every scraper. This is reasonable since we have no way to distinguish individual requests outside of the parse step anyways.

const config: ConfigInit = {
  input: ['username', 'password']
  scrapers: {
    login: {
      download: 'http://example.com/login?username={{ username }}&password={{ password }}',
      parse: {
        format: 'json',
        selector: 'session.token'
      }
    },
    pageBehindLogin: {
      download: {
        urlTemplate: 'http://example.com/account',
        headerTemplates: {
          cookie: 'token: {{{ login.lastValue }}}' // the important line
        }
      }
    }
  },
  run: {
    scraper: 'login',
    forEach: {
      scraper: 'pageBehindLogin'
    }
  }
}

or we can explicitly set variables. This feels less declarative so I am less inclined to use it

const config: ConfigInit = {
  scrapers: {
    login: {
      download: 'http://example.com/login?username={{ username }}&password={{ password }}',
      parse: {
        format: 'json',
        selector: 'session.token'
      },
      setValueAsGlobal: 'token'
    },
    pageBehindLogin: {
      download: {
        urlTemplate: 'http://example.com/account',
        headerTemplates: {
          cookie: 'token: {{{ globals.token }}}'
        }
      }
    }
  },
  run: {
    scraper: 'login',
    forEach: {
      scraper: 'pageBehindLogin'
    }
  }
}
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

No branches or pull requests

1 participant