爬虫入门操作

    技术2022-07-10  121

    存文件的三种方式:

    txt文件

    with open('目录.txt','a',encoding='utf-8') as f: f.write(alist+'\n')

    csv文件

    with open('qdzw.csv','w',encoding='utf-8') as f: writer = csv.writer(f,delimiter=',') writer.writerow(['title','author','cont']) with open('qdzw.csv','a',encoding='utf-8') as f: writer = csv.writer(f, delimiter=',') writer.writerow([title,author,cont])

    json文件

    lst = [] dic = {} dic['title'] = title # 这些字段都是根据爬取出来的字段定的 dic['author'] = author dic['cont'] = cont lst.append(dic) with open('qdzw.json', 'a', encoding='utf-8') as f: f.write(json.dumps(lst, indent=4, ensure_ascii=False))
    Processed: 0.047, SQL: 9