現在のクエリ文字列を「&」文字で分割して、さまざまなクエリ引数を取得できるようにしようとしています。これらの引数から、それらを別のファイル、つまり p_file.txt、blog_file.txt、portfolio_file.txt などに入れようとしています。クエリのリストを分割しようとして立ち往生していますが、それは不可能です。私は助けを求めています。
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()