0

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?

3
  • What is login_page_html? What does not working mean? Commented Jul 30, 2015 at 17:40
  • Or another duplicate: stackoverflow.com/questions/15119451/…. Commented Jul 30, 2015 at 17:40
  • My bad, I accidentally had page_html = ... instead of login_page_html, it's been fixed in the OP now. @alecxe thanks for the link, thought I searched thoroughly for the answer and I thought in python it doesn't matter if you define the functions before or after where you call them. Commented Jul 30, 2015 at 18:56

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.