我如何使用curl和php下载此链接

时间:2019-07-20 06:27:16

标签: php php-curl

无法使用curl PHP下载此链接 https://www.economy.gov.ae/PublicationsArabic/2%20%D9%86%D8%B4%D8%B1%D8%A9%20%D8%A7%D9%84%D8%B9%D9%84%D8%A7%D9%85%D8%A7%D8%AA%20%D8%A7%D9%84%D8%AA%D8%AC%D8%A7%D8%B1%D9%8A%D8%A9%20%D8%A7%D9%84%D8%B9%D8%AF%D8%AF%20199-%20%D8%A7%D9%84%D9%86%D8%B4%D8%B1%20%D8%B9%D9%86%20%D8%A7%D9%84%D8%B9%D9%84%D8%A7%D9%85%D8%A7%D8%AA%20%D8%A7%D9%84%D9%85%D9%82%D8%A8%D9%88%D9%84%D8%A9.pdf

尝试的基本卷曲无效,wget也无效

from collections import defaultdict, Counter

def makeDict():
    string = """abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890().,:;'" []//|\\!@#$%^&*_+-=<>?~`"""

    overall = defaultdict(Counter)
    dictionary = {}

    listofstuff = list(string)

    for i in listofstuff:
        dictionary[str(i)] = 0

    for a in listofstuff:
        overall[str(a)] = {1 : dictionary, 2 : dictionary, 3 : dictionary}

    return overall

空pdf或189字节

2 个答案:

答案 0 :(得分:0)

只是网站在获取请求之前使用发布请求,并且您需要在应用程序上具有一定的逻辑之前将其伪造,现在它可以正常工作

答案 1 :(得分:-1)

在使用curl之前尝试urldecode

 $ch = curl_init();
 $url = urldecode($url);
 curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
 curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
 curl_setopt($ch, CURLOPT_ENCODING, "utf-8");
 echo $output=curl_exec($ch);

 curl_close($ch);