【问题标题】:Why python requests have problem with lowering arguments为什么 python 请求在降低参数方面存在问题
【发布时间】:2026-01-05 10:15:01
【问题描述】:

我在 python 中获取系统参数,并且在添加 .lower() 后无法传递它们

我尝试了一些不同的解决方案,例如

list_join = ''.join(arg_list_split).lower()

list_join = str(arg_list_split).lower()

似乎 post request 无法识别我的 line 程序调用中的某些大写字母,

如果我像 python movie_find.py war spartacus 那样拨打电话 = 一切都很好 但是当我调用 python movie_find.py war Spartacus = 看起来它停止工作时,这意味着字符串参数没有正确传递给发布请求

#!/usr/bin/env python3
import requests, re, sys
from bs4 import BeautifulSoup as bs

url = 'https://alltube.tv/szukaj'

arg_list_split = sys.argv[1:]

list_join = ' '.join(arg_list_split)

s = requests.Session()
response = s.post(url, data={'search' : list_join})
soup = bs(response.content, 'html.parser')

for link in soup.findAll('a', href=re.compile('serial')):
    final_link = link['href']
    if all(i in final_link for i in arg_list_split): 
        print(final_link)

我希望通过程序调用获得结果,其中包含小写或大写或大写字母,所有这些都降低并传递给正确发布请求,然后从站点获取最终链接

【问题讨论】:

    标签: python-3.x python-requests arguments sys


    【解决方案1】:

    如果您使用大写字符串调用脚本,您将在表达式中比较大小写字符串

    if all(i in final_link for i in arg_list_split):
    

    这不会给你任何结果。

    您需要确保 arg_split_list 只包含小写字符串,例如,通过这样做

    arg_list_split = [x.lower() for x in sys.argv[1:]]
    

    【讨论】:

    • 哇,第一个答案成功了,谢谢,我找不到那个答案:)