python - python 列表中的值被替换

标签 python web-scraping

我正在尝试使用以下代码获取缩短的 URL 的实际 URL(我已将缩短的 URL 替换为其他代码,因为 stackoverflow 不允许它们)

url_list = ['https://stackoverflow.com/questions/62242867/php-lumen-request-body-always-empty', 'https://twitter.com/i/web/status/1269102116364324865']

import requests    
actual_list =[]

for link in url_list:
  response = requests.get(link)
  actual_url = response.url
  actual_list = actual_url
print(actual_list)

最后,actual_url 中只剩下最后一个 URL,但我需要每个 URL。有人可以告诉我我在这里做错了什么吗?

最佳答案

您需要将网址附加到列表中。

actual_list =[]
for link in url_list:
  response = requests.get(link)
  actual_url = response.url
  actual_list.append(actual_url)

关于python - python 列表中的值被替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62243095/

相关文章:

Python:为什么我的代码以全部大写结尾?

python - 如何让我的程序根据 key.is_pressed 语句播放声音?

python - 如何将异步操作映射到有序数据流并获得相同顺序的结果?

python - 美丽的汤 : AttributeError: 'NoneType' object has no attribute 'text'

javascript - 用于受密码保护的网站的 nodejs 网络抓取工具

python - 如果 DoubleVar 或 IntVar 为空,tkinter python 3.4 设置为零

python - 合并 2 个列表时 pd.DataFrame() 失败

python - 网页抓取 - 过滤结果

python - Web 抓取导致 403 禁止错误

javascript - 我如何使用 scrapy 来解析 JS 中的链接?