Python: Only writes last line of output

后端 未结 4 2081
耶瑟儿~
耶瑟儿~ 2021-01-29 01:05

Trying to write a program that extracts URLs from a website. The output is good, but when I try to write the output to a file, only the last record is written. Here is the code:

4条回答
  •  死守一世寂寞
    2021-01-29 01:57

    url = "msn.com"
    print("Parent:", url)
    f = open("f2.txt", "w",)
    for x in extractUrls(url):
        print("-", x)
        f.write( x )
    f.close()
    

提交回复
热议问题