Curl 应用于获取 HTTP 页面的简单示例 -> 将所有内容存储在 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)
这里是原始问题中的旧文本:
今天我想在一个非常简单的示例上应用 Curl 来获取 HTTP 页面 - 回顾 为了收获这个非常简单的数据,
请参阅这个完全简单的页面:http://www.aktive-buergerschaft .de/buergerstiftungsfinder 这里我们有一个 Foundations 列表:我们可以看到一堆(大约 1000 条 Foundations 记录)。嗯 - 我的目的是将数据存储在本地数据库中(最喜欢的数据库是 MySQL):
这是我的简单方法 - 缺少的是两个部分:结果的处理和解析器结果的存储 - 到MySQL-DB。这部分有点超出我的理解范围。
好吧,用 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: [email protected]
www.buergerstiftung-aachen.de
>> Weitere Details zu dieser Stiftung
链接“Weitere Details zu dieser Stiftung”,其内容为:英文 有关该基金会的更多详细信息”,
必须遵循此链接,并且(也)要解析结果。如果您点击该链接,那么您会看到:还有一些附加信息也应该存储!
好吧 - 现在需要什么:我需要有数组的详细信息任何人都可以放大上面可以看到的代码位 - 并给我一个提示!?我期待这个......
update: the answer from virtualeyes (below) looks pretty nice: but now a bit code-sanititzing should be applied:
$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);
and with the corrections we have something like the following:
$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);
see the additional infos from virtualeye... [a big thanks to 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)
here the old text from the original question:
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):
here is my simple approach - what is missing are two parts: The processing of the results and the storing of the results of the parser - into the MySQL-DB. This part goes somewhat over my head.
Well the result of the Fetching with Curl should be given to arrays - shouldn ´t it!? If someone can help me here i would be glad!
<?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 !?! ]
?>
see the example here on this page: (at the top)
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: [email protected]
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"
this link has to be followed and the results (also) to be parsed. If you follow the link then you see: There are some additional infos that should be stored too!
Well - what is needed now: I need to have the details for the arrays Can any body enlarge the codebits that can be seen above - and give me a hint!? I look forward to this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该适合你:
Something like this should work for you: