通过URL解析API CSV [英] Parse API CSV via URL

查看:636
本文介绍了通过URL解析API CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要处理的API数据的建议。我想知道什么是最好的方法来解析csv文件与下面的URL格式。

网址:网址... COM ../ .. API / CSV .. / .. 1234apikey = .. 123456ABC

我想处理结果和值插入到数据库中。

中的数据将改变加班,所以实现需要是动态的。

数据的格式是如下:

 位置,player.href,name.text,全面,信,天,命中,指标,网址
1,的javascript:无效(0);,杰米,1,URL
T2,的javascript:无效(0);,汤姆,3,A,1,68,URL
T2,的javascript:无效(0);,山姆,3,A,2,8,27,3,URL
T2,的javascript:无效(0);,乔,3,A,3,7,27,4,URL
5,的javascript:无效(0);,轻拍,2,A,4,7,28,5,URL
T6,的javascript:无效(0);,肖恩,1,A,5,6,29,6,URL


解决方案

编辑 - 我不知道,你不知道如何从API中提取数据。我会用file_get_contents()函数或卷曲查询网址。通常情况下

\r
\r

的file_get_contents(网址:网址... COM ../ .. API / .. CSV / .. 1234apikey = .. 123456ABC);

\r

\r
\r

我会用\\ n循环通过分割数据,然后通过,拆呢。在fo​​reach然后你可以拖放到任何你想要做一个MySQL表或

\r
\r

< PHP\r
\r
$数据=你的API数据;\r
$ splitlines =爆炸(\\ n,$数据);\r
\r
的foreach($ splitlines为$线)\r
{\r
$ linedata =爆炸('',$线);\r
$位置= $ linedata [0];\r
$球员= $ linedata [1];\r
...等等。\r
}

\r

\r
\r

I need advice on dealing with API data. I want to know what's the best approach to parse a csv file with the format of the URL below.

URL: URL…com../..api/..csv/..1234apikey=..123456ABC

I would like to process the results and insert the values into a database.

The data will change overtime, so the implementation needs to be dynamic.

The format of the data is below:

"position","player.href","name.text","total","letter","days","hits","index","url"
"1","javascript:void(0);","Jamie","1","url"
"T2","javascript:void(0);","Tom","3","A","1","68","url"
"T2","javascript:void(0);","Sam","3","A","2","8","27","3","url"
"T2","javascript:void(0);","Joe","3","A","3","7","27","4","url"
"5","javascript:void(0);","Pat","2","A","4","7","28","5","url"
"T6","javascript:void(0);","Sean","1","A","5","6","29","6","url"

解决方案

Edit - I didn't know you didn't know how to pull data from the API. I would use file_get_contents() or CURL to query the URL. Typically

file_get_contents("URL: URL…com../..api/..csv/..1234apikey=..123456ABC");

I would loop the data by splitting by "\n" and then split it by ",". In the foreach you could then drop it into a MySQL table or whatever you want to do.

<?php

$data = "your api data";
$splitlines = explode("\n",$data);

foreach($splitlines as $line)
{
	$linedata = explode(',',$line);
	$position = $linedata[0];
	$player = $linedata[1];
	... etc.
}

这篇关于通过URL解析API CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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