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
-
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 variable
text
and its seal gets inside the second blockif
, and it should be outside, judging by the logic. At the same time, the commentresult
stands 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)
Related questions
- How to get data-value from td in BS4 python
- python : Please help, I can't get data through Beautiful Soup
- Python Beautifulsoup How to get link from tag?
- python. Get the value of the Phone field
- python : Json parser from ready-made code
- python : The block on the authorized page is not parsed
- What parameters to pass for a POST request to solve a Python captcha
- python : data comparison not working
- 511 python requests response
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):