Python 解析屏蔽/缩短的URL twint正在从twitter上抓取

Python 解析屏蔽/缩短的URL twint正在从twitter上抓取,python,redirect,web-scraping,twitter,twint,Python,Redirect,Web Scraping,Twitter,Twint,我正在使用twint来抓取推特个人资料 运行此脚本时: c = twint.Config() c.Username = username c.Store_object = True c.Store_object_users_list = users c.Hide_output = True twint.run.Lookup(c) try: userna = users[0] except: conti

我正在使用
twint
来抓取推特个人资料

运行此脚本时:

    c = twint.Config()
    c.Username = username
    c.Store_object = True
    c.Store_object_users_list = users
    c.Hide_output = True
    twint.run.Lookup(c)
    try:
        userna = users[0]
    except:
        continue
    web = userna.url
我得到的是屏蔽/缩短的URL,而不是真实的URL。我怎样才能得到真正的网址

你有什么建议?

以下方法有效

import requests


resp = requests.head(short_link)
resp.status_code
true_url = resp.headers["Location"]
前言:此答案基于我的评估结果和发现(在最初版本中)


要将缩短的URL转换为它所代表的完整URL,您可以使用
twint
间接附带的软件包(这是您已经安装的
twint
所需的
googletransx
所需的,因此不需要
pip安装请求

,然后检查响应的
状态\u code
,然后读取
位置
标题;还有一些情况下,
位置
将出现在响应中,但在
HTTP 200 OK
的情况下则不会出现

导入请求
#Python请求教程的简短URL
简短的https://youtu.be/tb8gHvYlCFs'
res=requests.head(短url)
如果res.status_code==303:#“请参阅其他”
完整url=res.headers['location']
elif res.status_code==200:#“OK”
#让我们得出结论,短网址已经是我们正在寻找的
完整url=短url
其他:
#替换为您的错误处理:
断言(假)

我添加了一个小补丁,希望您能接受。