Created
June 10, 2018 13:50
-
-
Save chapinb/8133f073b7594d8648b8906aa0a57267 to your computer and use it in GitHub Desktop.
Quick demo script for parsing Google search strings from URL query string data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Quick script to open a text file of Google search URL query strings | |
and extract the typed search values. | |
Copyright 2018 Chapin Bryce. | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
""" | |
import sys | |
# Open file | |
with open(sys.argv[1]) as open_file: | |
# Iterate through the lines of the file | |
for raw_line in open_file: | |
# Remove padding (ie `\r\n`) | |
line = raw_line.strip() | |
# Split the line on the `&` to get individual key/value pairs | |
for component in line.split("&"): | |
# If we have an `=` character, we can get key and value | |
if "=" in line: | |
key, value = component.split("=") | |
# Otherwise, let's call the whole line a value. | |
# This data will not print, though can be used elsewhere | |
else: | |
key = "N/A" | |
value = line | |
# Only print if we see the known `q` key name | |
if key == 'q': | |
# Print the key and value using a format string | |
print("{}: {}".format(key, value)) | |
""" | |
Things to add: | |
============== | |
- Parse the %20 (and other URLEncoded characters) | |
- Read other common search engine formats | |
- Look into other values common/useful in the querystring | |
- Write to a CSV instead of printing | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sugexp=chrome,mod=9&client=chrome&hl=en-US&q=dead+drop+for+da | |
sugexp=chrome,mod=9&client=chrome&hl=en-US&q=dead+drop+for+dat | |
sugexp=chrome,mod=9&client=chrome&hl=en-US&q=dead+drop+for+data | |
sugexp=chrome,mod=9&sourceid=chrome&ie=UTF-8&q=dead+drop+for+data | |
sa=t&rct=j&q=dead%20drop%20for%20data&source=web&cd=1&ved=0CIMBEBYwAA&url=http%3A%2F%2Fdeaddrops.com%2F&ei=dUnZT975A8eX6QGP1NXKAg&usg=AFQjCNEp0PkaEGl8CgJhJ1bePuMmfADtKw | |
sugexp=chrome,mod=9&client=chrome&hl=en-US&q=pas | |
sugexp=chrome,mod=9&client=chrome&hl=en-US&q=paste+ | |
sugexp=chrome,mod=9&client=chrome&hl=en-US&q=paste+site | |
sugexp=chrome,mod=9&sourceid=chrome&ie=UTF-8&q=paste+site | |
sa=t&rct=j&q=paste%20site&source=web&cd=1&ved=0CFwQFjAA&url=http%3A%2F%2Fpastesite.com%2F&ei=u0nZT6yPGbCM6QH18enLAg&usg=AFQjCNEQIb0A9qLEEqRNpBg-ir02Gn8g-A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
q: dead drop for da | |
q: dead drop for dat | |
q: dead drop for data | |
q: dead drop for data | |
q: dead%20drop%20for%20data | |
q: pas | |
q: paste | |
q: paste site | |
q: paste site | |
q: paste%20site |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment