|
| 1 | +# referer-parser Python library |
| 2 | + |
| 3 | +This is the Python implementation of [referer-parser] [referer-parser], the library for extracting search marketing data from referer _(sic)_ URLs. |
| 4 | + |
| 5 | +The implementation uses the shared 'database' of known search engine referers found in [`search.yml`] [search-yml]. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | + pip install referer_parser |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Create a new instance of a Referer object by passing in the url you want to parse: |
| 14 | + |
| 15 | +```python |
| 16 | +from referer_parser import Referer |
| 17 | + |
| 18 | +referer_url = 'http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari' |
| 19 | + |
| 20 | +r = Referer(referer_url) |
| 21 | +``` |
| 22 | + |
| 23 | +The `r` variable now holds a Referer instance. The important attributes are: |
| 24 | + |
| 25 | +```python |
| 26 | +print(r.known) # True |
| 27 | +print(r.referer) # 'Google' |
| 28 | +print(r.search_parameter) # 'q' |
| 29 | +print(r.search_term) # 'gateway oracle cards denise linn' |
| 30 | +print(r.uri) # ParseResult(scheme='http', netloc='www.google.com', path='/search', params='', query='q=gateway+oracle+cards+denise+linn&hl=en&client=safari', fragment='') |
| 31 | +``` |
| 32 | + |
| 33 | +The `uri` attribute is an instance of ParseResult from the standard libraries `urlparse` module. |
| 34 | + |
| 35 | +## Contributing |
| 36 | + |
| 37 | +1. Fork it |
| 38 | +2. Create your feature branch (`git checkout -b my-new-feature`) |
| 39 | +3. Commit your changes (`git commit -am 'Add some feature'`) |
| 40 | +4. Push to the branch (`git push origin my-new-feature`) |
| 41 | +5. Create new Pull Request |
| 42 | + |
| 43 | +## Copyright and license |
| 44 | + |
| 45 | +The referer-parser Python library is copyright 2012 Don Spaulding. |
| 46 | + |
| 47 | +Licensed under the [Apache License, Version 2.0] [license] (the "License"); |
| 48 | +you may not use this software except in compliance with the License. |
| 49 | + |
| 50 | +Unless required by applicable law or agreed to in writing, software |
| 51 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 52 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 53 | +See the License for the specific language governing permissions and |
| 54 | +limitations under the License. |
| 55 | + |
| 56 | +[referer-parser]: https://github.com/snowplow/referer-parser |
| 57 | +[search-yml]: https://github.com/snowplow/referer-parser/blob/master/search.yml |
| 58 | + |
| 59 | +[license]: http://www.apache.org/licenses/LICENSE-2.0 |
0 commit comments