NameError: name 'value_from_name' is not defined
Question: I'm trying to use beautiful soup 4 to parse html for a login page and get
tokens from that page.

    
    
    import requests 
    from bs4 import BeautifulSoup
    
    session = requests.Session()
    
    login_page_html = BeautifulSoup(session.get('https://url.com',     verify=False).text)
    lsd = value_from_name('something', login_page_html)
    
    
    def value_from_name(name, soup):
        return soup.find(name=name)['value']
    

I got this to work in another program, but I'm not sure why it's not working
here. I'm new to python, guessing it's because I'm not passing the paramaters
correctly?


Answer: You are using the function before defining it. Define the function first,
before using it.

Example -

    
    
    import requests 
    from bs4 import BeautifulSoup
    
    
    def value_from_name(name, soup):
        return soup.find(name=name)['value']
    
    session = requests.Session()
    
    page_html = BeautifulSoup(session.get('https://url.com', verify=False).text)
    lsd = value_from_name('something', login_page_html)
    

