Url unshortner python and urilib Request

问题描述 投票:0回答:1

我正在托盘中取消一些已经缩短的网址。对于这种事情,我正在使用https://pypi.org/project/fake-headers/创建标题

但是我无法正常工作,我得到了400和406状态代码。

        url = 'http://   bit.ly   /377n4o6' #i had to add spaces end url is https://es.banggood.com/Xiaomi-Mi-A1-MiA1-Dual-Rear-Camera-5_5-inch-4GB-RAM-64GB-Snapdragon-625-Octa-core-4G-Smartphone-p-1196064.html      
        parsed = urllib.parse.urlparse(url)
        if parsed.scheme == '':
            url = 'http://' + url
            parsed = urllib.parse.urlparse(url)
        h = http.client.HTTPConnection(parsed.netloc, timeout=5)
        path = quote(parsed.path, safe='')

        header = Headers(
            browser="chrome",  # Generate only Chrome UA
            os="win",  # Generate ony Windows platform
            headers=True  # generate misc headers
            )
        #request is asking to have a parans, so I got one from another code.
        params = urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})

        h.request('HEAD', path,params, header.generate())
        response = h.getresponse()
        print(response.status)

失败的可能是什么问题?

感谢

python httpconnection
1个回答
0
投票
您可以使用requests module,然后获取重定向的历史记录,而URL缩短程序可以做到这一点……
© www.soinside.com 2019 - 2024. All rights reserved.