Get input value

Asked

Viewed 205 times

2

Hello I would like to know how I can get a value from a one-page input 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 take the content of "value", which changes with each request, and use it in the header for another Curl.

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

  • Friend, I need to get the value of the authurl of a link, this authurl changes in this such link every time I refresh the page, how to proceed ?

  • @Gennie having html (server response) can fetch value from input, this way and use it as you wish for future http requests. Look at the demonstrations

  • Miguel, I can’t understand, could you do another demo for me using a link in which you pull data from this link ?

  • @Gennie you have the link you want to do this parse, you can give me to take a look

  • I got this one at random::https://www.netflix.com/br/login

  • How do I give Curl (get) this link and get the value of "<input type="Hidden" name="withFields" value="accessToken,rememberme,nextpage" data-reactid="51"/><input type="Hidden" name="authURL" value="1526639860898.gm/544CBTGsGINJNknmU2CHt5w0=" data-reactid="52"/>"

  • The value of this input changes with each request

  • 1

    @Gennie, https://repl.it/repls/ZealousConventionalAnalysts

  • 1

    Thank you very much!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.