Get input value

1

Hello, I would like to know how to get a value from an input of a page after performing a curl with requests in python 3.6!

Example:

<input type="hidden" name="authURL" value="1526610106833.UG2TCP2ZiJ9HKXhlrlgybcdEBB0=" data-reactid="37"/>

I wanted to get the contents of the "value", which changes each request, and use it in the header for another curl.

    
asked by anonymous 18.05.2018 / 04:24

1 answer

1

If you want to do with regex:

import re

html = '<input type="hidden" name="authURL" value="1526610106833.UG2TCP2ZiJ9HKXhlrlgybcdEBB0=" data-reactid="37"/>'

match = re.compile('name="authURL" value="(.*?)"').search(html)
if match == None:
  print('Não encontrado')
else:
  print(match.group(1)) # 1526610106833.UG2TCP2ZiJ9HKXhlrlgybcdEBB0=

DEMONSTRATION

With BeautifulSoup (recommended):

from bs4 import BeautifulSoup as bs

html = '<input type="hidden" name="authURL" value="1526610106833.UG2TCP2ZiJ9HKXhlrlgybcdEBB0=" data-reactid="37"/>'

soup = bs(html, 'html.parser')
inp = soup.find('input', {'name': 'authURL'})
print(inp.get('value')) # 1526610106833.UG2TCP2ZiJ9HKXhlrlgybcdEBB0=

DEMONSTRATION

    
18.05.2018 / 09:37