Search code examples
python-3.xpython-requestsargumentssys

Why python requests have problem with lowering arguments


I'm getting system arguments in python, and have problem with passing them after adding .lower()

I have tried some different solutions like

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

or

list_join = str(arg_list_split).lower()

it seems like post request don't recognize some capital letters in my line program call,

if I make call like python movie_find.py war spartacus = everything is fine but when i make call python movie_find.py war Spartacus = looks like it stops working, it means that string arguments aren't properly passed to post request

#!/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)

I would like to get result as program call with small or upper or capitalized letters all those lowered and passed to post request properly and then get a final link from site


Solution

  • If you call the script with an uppercase string, you are comparing uppercase and lowercase strings in the expression

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

    which gives you no result.

    You need to make sure that arg_split_list contains only lowercase strings, for instance, by doing

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