M
M
Morrdor2020-08-07 13:07:56
Python
Morrdor, 2020-08-07 13:07:56

How to print all values ​​from input in python?

import xml.etree.ElementTree as et
import requests
from bs4 import BeautifulSoup
from multiprocessing import Pool

iterar = input ('How many domains you want to check: ')

domainlist = []  
try:
   iterar = int(iterar)
except ValueError:
  print('incorrect value')



if iterar <= 0:
  print('Please write a count of domains you want to be cheked')


i=0
while i<iterar:
  i=i+1
  allDomain = input(f'Enter Domain N{i}: ')

#Connection
result = requests.get(f'http://data.alexa.com/data?cli=20&dat=snbamz&url={allDomain}')
data_string = result.text
root = et.fromstring(data_string) 


rank = [item.attrib.get('RANK') for item in root.findall('.//REACH')]

print(f"Domain: \'{allDomain}\'")
print(f"Alexa Rank: {rank}".replace("[", "").replace("]", ''))

input()

How can I make it show all input values? In this case, only the last input from the user is displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SKEPTIC, 2020-08-07
@morrdor

Do this in this piece of code

i=0
while i<iterar:
  i=i+1
  allDomain = input(f'Enter Domain N{i}: ')
  domainlist.append(allDomain)

Do this in this piece of code:
while domainlist:
  domain = domainlist.pop(0)
  result = requests.get(f'http://data.alexa.com/data?cli=20&dat=snbamz&url={domain}')
  data_string = result.text
  root = et.fromstring(data_string) 
  
  
  rank = [item.attrib.get('RANK') for item in root.findall('.//REACH')]
  
  print(f"Domain: \'{domain}\'")
  print(f"Alexa Rank: {rank}".replace("[", "").replace("]", ''))

In general, it would be desirable for you to learn the basics of python
. The end result:
import xml.etree.ElementTree as et
import requests
from bs4 import BeautifulSoup
from multiprocessing import Pool

iterar = input ('How many domains you want to check: ')

domainlist = []    #List in which we append domains from input
try:
   iterar = int(iterar)
except ValueError:
  print('incorrect value')



if iterar <= 0:
  print('Please write a count of domains you want to be cheked')


i=0
while i<iterar:
  i=i+1
  allDomain = input(f'Enter Domain N{i}: ')
  domainlist.append(allDomain)

while domainlist:
    domain = domainlist.pop(0)
    result = requests.get(f'http://data.alexa.com/data?cli=20&dat=snbamz&url={domain}')
    data_string = result.text
    root = et.fromstring(data_string)


    rank = [item.attrib.get('RANK') for item in root.findall('.//REACH')]

    print(f"Domain: \'{domain}\'")
    print(f"Alexa Rank: {rank}".replace("[", "").replace("]", ''))

input()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question