拆分char上的查询字符串以获取不同的参数;Python:

2024-06-23 03:42:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望拆分'&;字符上的当前查询字符串,以便获得不同的查询参数。根据这些论点,我希望把它们放入不同的文件,即_文件.txt,博客_文件.txt,投资组合_文件.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()

Tags: 文件oftheinfromtxturlfor

热门问题