Home>

When requesting the number 79999999999, 2 results are displayed. But if the result on the site is only 1, as in the case of 79062296890, then for some reason the result is not displayed.

phone_main= '79062296890'
epieos_url= 'https://tools.epieos.com/skype.php'
epieos_params= {'data':f'+{phone_main}'}
epieos_response= requests.post(epieos_url, data=epieos_params)
epieos_soup= BeautifulSoup(epieos_response.text, 'html5lib')
epieos_skype= epieos_soup.findAll('div', {'class': 'col-md-4 offset-md-4 mt-5 pt-3 border'})
skype_result_0= ''
length=len(epieos_skype)
if length>=1:
    skype_find_0= epieos_skype[0].text.strip()
    skype_name_0= skype_find_0.split('Id :')[0].strip()
    skype_name_0= skype_name_0.replace("Name : ","")
    skype_name_0= skype_name_0.replace("Skype","")
    skype_name_0= skype_name_0.replace(">",""")
    skype_name_0= skype_name_0.replace("<",""")
    skype_login_0= skype_find_0.split('Id :')[1].strip()
    skype_result_0= f'\n<b>Skype:</b> <a href="https://transitapp.com/redirect.html?url=skype://{skype_login_0}?chat">{skype_login_0}</a> | {skype_name_0}'
skype_result_1= ''
length=len(epieos_skype)
if length>=2:
    skype_find_1= epieos_skype[1].text.strip()
    skype_name_1= skype_find_1.split('Id :')[0].strip()
    skype_name_1= skype_name_1.replace("Name : ","")
    skype_name_1= skype_name_1.replace("Skype","")
    skype_name_1= skype_name_1.replace(">",""")
    skype_name_1= skype_name_1.replace("<",""")
    skype_login_1= skype_find_1.split('Id :')[1].strip()
    skype_result_1= f'\n<b>Skype:</b> <a href="https://transitapp.com/redirect.html?url=skype://{skype_login_1}?chat">{skype_login_1}</a> | {skype_name_1}'
result
    text= f""
    if skype_result_0:
        text += f'{skype_result_0}'
    if skype_result_1:
        text += f'{skype_result_1}'
    print(text)
  • Answer # 1

    The logic of your script is not entirely clear to me. In this case, you can get a maximum of 2 users, since I did not see a loop in your code. This script can be simplified using css selectors (there is no error handling in the code):

    def get_skypes(number):
        epieos_url= 'https://tools.epieos.com/skype.php'
        epieos_params= {'data':number}
        epieos_response= requests.post(epieos_url, data=epieos_params)
        epieos_soup= BeautifulSoup(epieos_response.text, 'html5lib')
        users= epieos_soup.select('div.col-md-4.offset-md-4.mt-5.pt-3.border') # Select all divs with the following classes
        for user in users:
            skype_name= user.select('p')[1].text.replace('Name : ','') # Select second div
            skype_login= user.select('p')[2].text.replace('Skype Id : ','') # Select third div
            print(f'\n<b>Skype:</b> <a href="https://transitapp.com/redirect.html?url=skype://{skype_login}?chat">{skype_login}</a> | {skype_name}')
    get_skypes("79999999999")
    
  • Answer # 2
    if length >=1:
            ...
        if length>=2:
            ...
        result
            text= f""
            if skype_result_0:
                text += f'{skype_result_0}'
            if skype_result_1:
                text += f'{skype_result_1}'
            print(text)
    

    Indentation is important. Here you have an extra indent and all the code with the formation of a variabletextand its seal gets inside the second blockif, and it should be outside, judging by the logic. At the same time, the commentresultstands with the correct indentation, but it does not affect anything, the comments are simply skipped by the interpreter. Remove extra indent:

    if length >=1:
            ...
        if length>=2:
            ...
        result
        text= f""
        if skype_result_0:
            text += f'{skype_result_0}'
        if skype_result_1:
            text += f'{skype_result_1}'
        print(text)