繁体   English   中英

php cURL忽略url中的变量

[英]php cURL ignoring variables in url

我正在研究一个爬网脚本,以从网上商店中读取评分。

卷曲部分现在给我带来了麻烦,因为它没有检索正确的内容。

我使用ajax脚本从数据库中批量选择URL。 我为curl提供了带有评级的正确URL,但是Curl正在检索页面中没有可变部分的页面。

这是我要传递给Curl的URL: $actualurl

http://www.domain.com/epages/xxx.sf/de_DE/?ObjectPath=/Shops/15456062/Products/%22Briefkastenst%C3%A4nder%20Bobiround%22/SubProducts/%22Briefkastenst%C3%A4nder%20Bobiround% 20gr%C3%BCN%20RAL6005%22&ViewAction这一= ViewProductRating

(这是我要从中读取所有6个评分(Produktbewertungen)的页面。)

但是通过curl调用,我从该页面获取内容,这与没有viewAction的情况相同,我回显了输出

http://www.domain.com/epages/xxx.sf/de_DE/?ObjectPath=/Shops/15456062/Products/%22Briefkastenst%C3%A4nder%20Bobiround%22/SubProducts/%22Briefkastenst%C3%A4nder%20Bobiround% 20gr%C3%BCN%20RAL6005%22

我的Curl调用看起来像这样:

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_USERAGENT, $agent);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_URL, $actualurl);              
            //read content of $url
            $result = curl_exec ($ch);
            curl_close ($ch);

为什么Curl忽略了url的最后一部分(使用&ViewAction=ViewProductRating

非常感谢您,我还是新手!

编辑

我从4个部分构建了上述网址。 这些部分如下:

$domainroot: http://www.domain.com/
$objectpath: epages/xxx.sf/de_DE/?ObjectPath
$ratingurl: %3D%2FShops%2F15456062%2FProducts%2F%2522Briefkastenst%25C3%25A4nder%2520Bobiround%2522%2FSubProducts%2F%2522Briefkastenst%25C3%25A4nder%2520Bobiround%2520gr%25C3%25BCn%2520RAL6005%2522%26amp%3B
$viewratings: ViewAction=ViewProductRating

最后,我将它们链接在一起:

$actualurl = $domainroot.$objectpath.$ratingurl.$viewratings;

查询字符串的第一个参数应正确编码:

$queryString = 'ObjectPath=%2FShops%2F15456062%2FProducts%2F%22Briefkastenst' .     
'%C3%A4nder+Bobiround%22%2FSubProducts%2F%22Briefkastenst' . 
'%C3%A4nder+Bobiround+gr%C3%BCn+RAL6005' 
'&ViewAction=ViewProductRating';

非常感谢你的帮助! 你让我今天一整天都感觉很好!

并感谢任何尝试提供帮助的人!

确实是&人物搞砸了。 当以某种方式在数据库中输入网址时,脚本具有&到& ,必须将其改回

$ratingurl = str_replace('&','&',$ratingurl);

该URL最初是使用preg_match_all获取的,并直接输入到数据库中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM