如何将网站数据记录为csv格式 [英] how to record website data into csv format

查看:98
本文介绍了如何将网站数据记录为csv格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我正在寻找从websitephoton读取数据的指南。 &安培;加载到csv文件。每当新的供应商选择或类型转换数据应与新表一起记录到同一个Excel中时。有些人可以指导如何开始使用python

此代码用于开发数据库。有没有简单的方法可以做到这一点。



http: //www.photon.info/photon_site_db_solarmodule_en.photon [ ^ ]

解决方案

我很抱歉,你有什么具体的想法?你的说明有点不清楚。



这是我用来从网站上提取数据的一些python 3.4代码。它基本上从站点提取数据,然后将其保存为txt文件。我已经将代码更改为.csv



它将是不完整的,需要校对和修改,但它应该为您获取csv数据的基本开始。



 savePath = '  C:/' +#whereever  save  data 
z = [] #list of 网站子域名
x 范围内( 0 ,len(z)):
print ' 当前拉动',z [x])
urlToVisit = ' http://www.photon.info/' + z [x]
websiteFile = []

sourceCode = urllib.request.urlopen(urlToVisit) 。 read ()。decode()
spl itSource = sourceCode.split(' \ n'
for eachLine in splitSource:
' '''做你的事' '''

completeName = os.path。 join (savePath,z [x] + ' 。csv'
open (completeName,' w' as file:
for eachLine in websiteFile:
file .write( {} \\\
.format(eachLine))


Dear all,

I am looking for guideline to read data from websitephoton . & load into csv file. Whenever new supplier selection or typesection change data should recorded into same excel with new sheet. Can some guide how to get started using python
This code to develop for database. Is there any easy method to do it will be appreciable.

http://www.photon.info/photon_site_db_solarmodule_en.photon[^]

解决方案

Hi, I'm so sorry, what specifically are you looking to do? Your instructions are a bit unclear.

Here is some python 3.4 code that I use to pull data from websites. It basically pulls data from a site and then saves it as a txt file. I have changed the code to something for .csv

It will be incomplete and need proofing and modifying but it should get the basic beginnings of getting data in csv for you.

savePath = 'C:/' + # whereever you save data
z = [] #list of website sub domains
for x in range (0, len(z)):
    print('Currently Pulling', z[x])
    urlToVisit = 'http://www.photon.info/' + z[x]
    websiteFile =[]

    sourceCode = urllib.request.urlopen(urlToVisit).read().decode()
    splitSource = sourceCode.split('\n')
    for eachLine in splitSource:
    '''' do your thing ''''
        
    completeName = os.path.join(savePath, z[x]+'.csv')
    with open(completeName, 'w') as file:
          for eachLine in websiteFile:
              file.write("{}\n".format(eachLine))


这篇关于如何将网站数据记录为csv格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆