python数据写入csv问题

来源:互联网 发布:网络基础技术视频教程 编辑:程序博客网 时间:2024/05/30 13:41

本人python小白,最近在研究爬虫方面,爬取了每日价格行情,北京站的网站行情信息。但是怎么写都写入不了CSV,求大神指点!以下是我代码

import requestsimport pandasimport csvfrom bs4 import BeautifulSouppage=1for page in range(20000):    url = "http://www.xinfadi.com.cn/marketanalysis/0/list/{}.shtml?prodname=&begintime=2016-1-01&endtime=2017-12-21".format(page)    #print(url)    response=requests.get(url)    response.encoding='UTF-8'    html=response.text    soup = BeautifulSoup(html, 'html.parser')    a=soup.find('table',attrs={'class':'hq_table'})    rows=a.find_all('tr')    #print(rows)    for row in rows:        #print(row)        cell = [i.text for i in row.find_all('td')]        del cell[-1]        print(cell)    page=page+1

原创粉丝点击