python - 使用 **requests.get** 和 python 来处理 HTTP 重定向?
问题描述
我在 python 上的请求模块有问题,当用户在我的基本网络抓取应用程序的网页上输入 url 时,请求模块不处理重定向 [例如:http ://www.yahoo.com - -> ie.yahoo.com] 破坏应用程序。按照代码片段,谢谢
if request.method == 'POST' and form.validate():
# the following are the data from the init form
url = form.url.data
email = form.email.data
# defining a new variable taking as input the values from the init form
mymsg=[{
"url": url,
"email" : email,
}]
# insert the list into the mongo db
x = mycol.insert_many(mymsg), print("inserting this item: ", mymsg, "in the database called ", mycol)
url1="http://"+url #making sure the parser will get the HTTP://WWW.EXAMPLE.COM syntax
result = requests.get(url1)
print("the requested url is: ",url1)
print(result.status_code)
print(result.headers)
解决方案
推荐阅读
- jquery - 如何使用 jquery 循环响应
- function - 错误:在项目中运行任何脚本时出现“找不到服务:加上 v1”。如何解决?
- javascript - 异步函数和对象参数并发
- ios - 为什么我的 UITableView 对于高分辨率图像滚动不那么流畅
- c# - 用于使用 xUnit 测试 API 端点的 HostBuilder 设置
- c# - 我在这个 for 循环任务中挣扎
- php - 部分 Paypal IPN 脚本和下面的结果。为什么 ["notify_version"]=> string(11) "UNVERSIONED" 会导致 ¬ify_version=UNVERSIONED?
- javascript - 对 .net 核心服务器的媒体范围请求失败
- celery - 气流芹菜工人:命令返回非零退出状态2
- java - 产出不如预期 - 零息债券计算器