English 中文(简体)
Curl应用于一个简单的例子,该例子获得一个HTTP页面->将所有内容存储在MySQL数据库中
原标题:Curl applied on a simple example that gets a HTTP page ->storing all in a MySQL-DB

更新:virtualeyes(如下)的答案看起来很好:但现在应该应用一点代码清理:

$ch = curl_init("http://www.aktive-buergerschaft.de/buergerstiftungsfinder");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$buffer = curl_exec($ch);
curl_close($ch);
$result = explode(",", $buffer);
print_r($result); 

经过修正,我们得到了如下内容:

$ch = curl_init("http://www.aktive-buergerschaft.de/buergerstiftungsfinder");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$buffer = curl_exec($ch);
curl_close($ch);
$result = explode(",", $buffer);
foreach($result as $k => $v) {echo $k." ".$v} 
if $v is itself an array) 
   // print_r($result);

请参阅virtualeye的其他信息。。。[非常感谢Virtualeye]

yes, print_r just prints out the response, 
in this case presumably as an array (if viewing the output in web browser, 
do view-source to see structured array). 
Depending on num dimensions, we could do, 
foreach($result as $k => $v) {echo $k." ".$v} 
to view and work with data 
(adding sub foreach loops accordingly; i.e. 
if $v is itself an array) 

这里是原问题的旧文本:

today i want to apply Curl on a very simple example that gets a HTTP page - review in order to harvest the data of this pretty simple

see this totally easy page: http://www.aktive-buergerschaft.de/buergerstiftungsfinder here we have a list of Foundations: We can see a bunch (approx 1000 records on Foundations). Well - my intention is to store the data in a locally database (favourite db is MySQL):

这是我的简单方法——缺少两个部分:结果的处理和解析器结果的存储——到MySQL数据库中。这部分有点超出我的想象。

那么,用Curl获取的结果应该给数组——不是吗!?如果有人能在这里帮我,我会很高兴的!

<?php
//
// A very simple example that gets a HTTP page.
//

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, "http://www.aktive-buergerschaft.de/buergerstiftungsfinder");
curl_setopt ($ch, CURLOPT_HEADER, 0);


curl_exec ($ch);

curl_close ($ch);

// well here i want to put the results into an array... [multidimensioal or not !?! ]

?>

请参阅本页上的示例:(顶部)

Bürgerstiftung Lebensraum Aachen
rechtsfähige Stiftung des bürgerlichen Rechts
Ansprechpartner: Hubert Schramm
Alexanderstr. 69/ 71
52062 Aachen
Telefon: 0241 - 4500130
Telefax: 0241 - 4500131
Email: info@buergerstiftung-aachen.de
www.buergerstiftung-aachen.de
>> Weitere Details zu dieser Stiftung 

The link "Weitere Details zu dieser Stiftung" which is: in english More details to this Foundation"

必须遵循此链接,并对结果进行解析。如果你点击链接,你会看到:还有一些额外的信息也应该存储!

好吧,现在需要什么:我需要数组的细节。任何人都可以放大上面可以看到的代码集吗?并给我一个提示!?我期待着。。。

最佳回答

这样的东西应该对你有用:

$ch = curl_init("http://www.aktive-buergerschaft.de/buergerstiftungsfinder");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$buffer = curl_exec($ch);
curl_close($ch);
$result = explode(",", $buffer);
print_r($result);
问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签