Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import requests, lxml.html
  2. from bs4 import BeautifulSoup
  3.  
  4. ## defines the session object as 's'
  5. s = requests.session()
  6.  
  7. ## creates a session begin, and navigates to the login page
  8. login = s.get('http://1.1.1.1/login.asp')
  9.  
  10. ## parses the login page for processing
  11. login_html = lxml.html.fromstring(login.text)
  12.  
  13. ## declares the login form field xpath
  14. inputs = login_html.xpath(r'//form//input')
  15.  
  16. ## attribute variables set for form fields
  17. form = {x.attrib["name"]: x.attrib["value"] for x in inputs}
  18.  
  19. ## defines the username and password for login
  20. form['username'] = 'root'
  21. form['password'] = 'crown'
  22.  
  23. ## posts the username and password to the form
  24. response = s.post("http://1.1.1.1/login.asp", data=form)
  25.  
  26. ## navigates to the system info page to scrape the data
  27. r = s.get("http://1.1.1.1/sysinf.asp")
  28.  
  29. ## defines the soup as the page text, and provides the parser argument
  30. soup = BeautifulSoup(r.text, "html.parser")
  31.  
  32. ## loops through each instance of <tr> and prints the contents
  33. for tr in soup.find_all('tr'):
  34.     print(tr.contents)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement