Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests, lxml.html
- from bs4 import BeautifulSoup
- ## defines the session object as 's'
- s = requests.session()
- ## creates a session begin, and navigates to the login page
- login = s.get('http://1.1.1.1/login.asp')
- ## parses the login page for processing
- login_html = lxml.html.fromstring(login.text)
- ## declares the login form field xpath
- inputs = login_html.xpath(r'//form//input')
- ## attribute variables set for form fields
- form = {x.attrib["name"]: x.attrib["value"] for x in inputs}
- ## defines the username and password for login
- form['username'] = 'root'
- form['password'] = 'crown'
- ## posts the username and password to the form
- response = s.post("http://1.1.1.1/login.asp", data=form)
- ## navigates to the system info page to scrape the data
- r = s.get("http://1.1.1.1/sysinf.asp")
- ## defines the soup as the page text, and provides the parser argument
- soup = BeautifulSoup(r.text, "html.parser")
- ## loops through each instance of <tr> and prints the contents
- for tr in soup.find_all('tr'):
- print(tr.contents)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement