Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. from bs4 import BeautifulSoup # parsing
  2.  
  3. html = """
  4. <html>
  5. <head id="Head1"><title>Title Page</title></head>
  6. <body>
  7. <form id="formS" action="login.asp?dx=" method="post">
  8.  
  9. <input type=hidden name=qw1NWJOJi/E8IyqHSHA== value='gDcZHY+nV' >
  10. <input type=hidden name=sfqwWJOJi/E8DFDHSHB== value='kgDcZHY+n' >
  11. <input type=hidden name=Jsfqw1NdddfDDSDKKSL== value='rNg4pUhnV' >
  12. </form>
  13.  
  14. </body>
  15.  
  16. </html>
  17. """
  18.  
  19. html_proc = BeautifulSoup(html)
  20.  
  21. print html_proc.find("input", value=True)["value"]
  22. > gDcZHY+nV
  23.  
  24. print html_proc.find("input", name=True)["name"]
  25. > TypeError: find() got multiple values for keyword argument 'name'
  26.  
  27. print html_proc.findAll("input", value=True, attrs={'value'})
  28. > []
  29.  
  30. print html_proc.findAll('input', value=True)
  31. > <input name="qw1NWJOJi/E8IyqHSHA==" type="hidden" value="gDcZHY+nV">
  32. > <input name="sfqwWJOJi/E8DFDHSHB==" type="hidden" value="kgDcZHY+n">
  33. > <input name="Jsfqw1NdddfDDSDKKSL==" type="hidden" value="rNg4pUhnV">
  34. > </input></input></input>, <input name="sfqwWJOJi/E8DFDHSHB==" type="hidden"
  35. > value="kgDcZHY+n">
  36. > <input name="Jsfqw1NdddfDDSDKKSL==" type="hidden" value="rNg4pUhnV">
  37. > </input></input>, <input name="Jsfqw1NdddfDDSDKKSL==" type="hidden" value="rNg4p
  38. > UhnV"></input>
  39.  
  40. print [(element['name'], element['value']) for element in html_proc.find_all('input')]
  41.  
  42. [('qw1NWJOJi/E8IyqHSHA==', 'gDcZHY+nV'),
  43. ('sfqwWJOJi/E8DFDHSHB==', 'kgDcZHY+n'),
  44. ('Jsfqw1NdddfDDSDKKSL==', 'rNg4pUhnV')]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement