替代iFrame从外部网站或表单提取实际数据 [英] Alternative to iFrame to pull in actual data from an external website or form

查看:122
本文介绍了替代iFrame从外部网站或表单提取实际数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧......我会尽力完成我的问题(所以,对于冗长的抱歉)......我一直在尝试在网络上搜索一个理想的解决方案。我建立了我们公司的网站(自学),事情已经开始与一些很好的CSS和PHP包括我的页眉和页脚,并准备使用一些媒体查询在我的CSS与不同的浏览器大小/分辨率,并得到一些很好的响应式网页设计。作为我们行业的产品供应商,我们将产品数据上传到名为Sage的服务中。他们为我们提供了一个我们可以使用的个人网站,它提供了我们提供给他们的产品数据。但是,他们的网站设计不是很好,我们只想将产品数据放入我们自己的现有网站。



目前,我们的网站页面为每个产品类别只是使用带有指向由结果生成的链接的src URL的iframe他们为我们提供的Sage网站上的搜索表单。显然,这不是很好,因为它拉动数据的速度很慢,而且我的iframe的大小必须适合最大高度,因为我不想为iframe滚动条。



再一次,我自学成就了网络开发,我唯一的工具是健康的谷歌数据......只是阅读源代码,所以如果您有任何建议,请详细说明。



我在这个网站上发现了一些其他人发布的东西,它实际上几乎适用于我,使用下面的代码(我正在测试这个URL (如果你想看看发生了什么)。



它使用下面的代码:
$ b

 <?php $ ch = curl_init(); 
curl_setopt($ ch,CURLOPT_URL,http: //www.promoplace.com/ws/ws.dll/StartSrchDistID=36182&ProdSelect=&Srching=1&CatName=Pens&catmoveto=Pens&category=221&keywords=&itemnum=&LoP=& HiP =& Qty =& Search.x = 44& Search.y = 22& Search = submit& GlobalSearch =);
curl_setopt($ ch,CURLOPT_HEADER,0);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,TRUE);?>
<?php $ result = curl_exec($ ch);
curl_close($ ch);?>
<?php $ result = preg_replace(#(< \ s * a \ s + [^>] * href \s * = \ s * [\'''])(?! http)([^ \ '>] +([\' >] +)#,$ 1http ://www.promoplace.com/$2$3',$ result);
echo $ result?>

如果你看看我的测试页面......数据已经过时了,但是外部图像不会显示,并且当您点击查看更多详细信息时,它会将外部域后面的正确实际链接数据附加到MY域,该域指向存在于外部但不在我的域中的目录。很显然,因为这些图像正在使用为本地目录编写的链接。我假设上面的$ results = preg_replace ..... ...命令以某种方式纠正了这种情况,所以也许我做错了,而且我已经差不多了。



如果任何人有任何想法,或更好,更干净的方式来实现这一点,你的帮助将非常感激。如果你不想使用iframe,而且你正在使用iframe,那么你就可以使用iframe了。

jQuery,你可以做这样的事情。请尝试以下代码:

而不是iframe标记使用div标记

 < div id =divId>< / div> 

将这段代码放入您的< head> tag

 < head> 
< script type ='text / javascript'src ='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver = 1.4'>< /脚本>

< script type ='text / javascript'>
$(document).ready(function(){
$('#divId')。load(你必须加载的目标网站的网址);
});
< / script>
< / head>

所有来自目标网站或网页(指定网址)的内容都会插入 #divID div标记。希望这可以帮助。一切顺利!


OK... I'll try to be complete with my question (so, sorry for the lengthiness)... I've been trying to search all over the web for an ideal solution. I build our company's web site (self taught) and things are starting to come together with some nice css and php includes for my header and footer, and getting ready to use some Media Queries in my CSS with different browser sizes/resolutions and get some nice responsive web design going. As a product supplier in our industry, we upload product data into a service called Sage. They provide us with a personal website we CAN use that pulls in our product data that we give them. However, their site design isn't great and we'd like to just pull in the product data into our own existing site.

Currently our site pages for each product category just uses an iframe with the src URL pointing to the link generated by the results of the search form on the Sage site they provide us. Obviously this isn't great since it's slow to pull the data in, and my iframe has to be sized to always fit the max height since i don't want scroll bars for the iframe.

Again, I am self taught with web development with my only tools being a healthy amount of google... and just reading source code, so if you have any recommendations, please be specific and detailed.

I have found something on this site posted by someone else that actually ALMOST works for me using the following code (I am testing at this URL (if you want to see whats happening).

It's using the following code:

<?php $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.promoplace.com/ws/ws.dll/StartSrchDistID=36182&ProdSelect=&Srching=1&CatName=Pens&catmoveto=Pens&category=221&keywords=&itemnum=&LoP=&HiP=&Qty=&Search.x=44&Search.y=22&Search=submit&GlobalSearch=");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); ?>
<?php $result = curl_exec($ch);
curl_close($ch); ?>
<?php $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+([\"'>]+)#",'$1http://www.promoplace.com/$2$3', $result);
echo $result ?>

If you look at my test page... the data is coming over well enough, but the external images don't display, and when you click through to view "more details" it appends the correct actual link data that should come after the external domain to MY domain, which points to a directory that exists externally, and not on my domain. It's obviously because the images are using links written for the directory locally. I am assuming that the $results = preg_replace..... ... command above is to in some way correct this, so maybe I am doing it wrong and I'm almost there already.

If anyone has any ideas, or a better, cleaner way to accomplish this, your help would be really greatly appreciated. I am really learning a lot, and enjoying it all.

解决方案

If you don't want to use iframe and you are using jQuery, you can do something like this. Try the following code:

Instead of an iframe tag use div tag

<div id="divId"></div>

Place this code inside your <head> tag

<head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=1.4'></script>

<script type='text/javascript'>
$(document).ready(function (){
$('#divId').load(url of target website what you must load);     
});
</script>
</head>

All the contents from target site or page(specified url) will be inserted inside the #divID div tag. Hope this helps. All the best!

这篇关于替代iFrame从外部网站或表单提取实际数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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