I'm looking to split the current query string on a '&' char so I can get different query arguments. From those arguments I am looking to put them into different files, i.e. p_file.txt, blog_file.txt, portfolio_file.txt, etc. I have been stuck trying to split a list of queries but it is not possible. I am open for help.
def parse_file():
# Open the file for reading
infile = open("URLlist.txt", 'r')
# Read every single line of the file into an array of lines
lines = infile.readlines()
# For every line in the array of lines, do something with that line
for line in lines:
# The lines we get back from readlines will have a newline
# character appended. So, let's strip that out as we parse
# the URL from the line into its components
line = line.strip()
url = urlparse(line)
# If the url has a query component...(ie. url.query)
if url.query:
# ...then print it out! We need to strip the trailing newline
# character from the url query, because urlparse doesn't do that
# for us.
queryvars = url.query
print queryvars
#for q in queryvars:
#print q
parse_file()
queryvars = url.query.split('&')work?{ 'p': ['49'], 'attachment_id': ['32'] }. You can then iterate over that with e.g.for key in queryvars: filename = key + '_file.txt' [...].url = parse_qsl(urlparse(line)[4])for key in url: p_file = key + 'p_file.txt'