Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门
https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6EmUbbW&id=564564604865
# -*- coding: utf-8 -*- """ Created on Sat May 7 09:32:30 2016 @author: daxiong """ import requests,bs4,csv,time,selenium from selenium import webdriver site1="http://118.114.237.85:8081/searchbio.aspx" charset="gb2312" browser=webdriver.Firefox() browser.get(site1) elems=browser.find_elements_by_class_name("tb") elems1= elems[1:] content=[i.text for i in elems1] #功能:将list对象N等分 def div_list(ls,n): if not isinstance(ls,list) or not isinstance(n,int): return [] ls_len = len(ls) if n<=0 or 0==ls_len: return [] if n > ls_len: return [] elif n == ls_len: return [[i] for i in ls] else: j = int(ls_len/n) ls_return = [] for i in range(0,(n-1)*j,j): ls_return.append(ls[i:i+j]) #算上末尾的j+k ls_return.append(ls[(n-1)*j:]) return ls_return def Write_table_to_csv(fileName,list_tableContent): #对列表格式修改,字符串写入的格式不对 file=open(fileName,'w',newline='') writer1=csv.writer(file) writer1.writerows(list_tableContent) file.close() content1=div_list(content,20) Write_table_to_csv("1.csv",content1)