Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. from LibrusMobile import app
  2. from flask import render_template, request
  3. from core.forms import LoginForm
  4. from core.utils import Site
  5. import lxml.html
  6.  
  7. @app.route('/', methods=['GET', 'POST'])
  8. def main_page():
  9. form = LoginForm()
  10. if request.method == 'POST':
  11. username=request.form['username']
  12. password=request.form['password']
  13. path=Site.user_path
  14. s=Site.login(username, password)
  15. url='https://link.com/index'
  16. user_response=Site.get_content(Site, s, url, path)
  17. user=', '.join([str(x) for x in user_response])
  18.  
  19. context={
  20. "user": user.replace("(", "- "),
  21. }
  22. return render_template("start_page.html", context=context)
  23. return render_template("index.html", form=form)
  24.  
  25. @app.route('/marks')
  26. def marks():
  27. url='https://link.com/marks'
  28. #Here i have a problem
  29. return render_template("marks.html")
  30.  
  31. import requests
  32. import lxml.html
  33.  
  34.  
  35. class Site():
  36. user_path = '//*[@id="user-section"]/b/text()[1]'
  37.  
  38. @staticmethod
  39. def login(login, passwd):
  40. url = 'https://link.com/login'
  41. with requests.session() as s:
  42. log_in=s.get(url)
  43. log_in_html= lxml.html.fromstring(log_in.text)
  44. hidden_inputs = log_in_html.xpath(r'//form//input[@type="hidden"]')
  45. form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
  46. form['login']=login
  47. form['passwd']=passwd
  48. request=s.post(url, data=form, stream=True)
  49. return s
  50.  
  51.  
  52.  
  53. def get_content(self, session, url, path):
  54. response=session.get(url)
  55. b=lxml.html.fromstring(response.text)
  56. text=b.xpath(path)
  57. return text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement