读取csv文件 通过csv.reader()和DictReader()两个函数 reader()函数返回一个迭代器 会包含表头 通过next函数可以跳过,但是它只能通过下标访问数据: DictReader()函数返回一个字典,不包含表头,可以通过键名访问!! import csv # with open('1 (2).csv','r') as fp: # reader=csv.reader(fp) # # next(reader) # for x in reader: #
使用Xpath和BeautifulSoup来解析网页可以说真的很简便. import requests from bs4 import BeautifulSoup from random import choice url = 'https://book.douban.com/tag/%E7%BC%96%E7%A8%8B' ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like G