我希望将当前查询字符串拆分为 '&' 字符,以便获得不同的查询参数。从这些论点中,我希望将它们放入不同的文件中,即 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()