How to get the hidden input's value with beautifulsoup?

input type=hidden value
jquery get hidden input value
html hidden text
input type=hidden not working
html input hidden required
jquery find hidden element
get hidden field value in jquery
get hidden field value in php

In python3 I want to extract information from a page using requests and beautifulsoup

import requests
from bs4 import BeautifulSoup

link = "https://portal.stf.jus.br/processos/listarPartes.asp?termo=AECIO%20NEVES%20DA%20CUNHA"

try:
    res = requests.get(link)
except (requests.exceptions.HTTPError, requests.exceptions.RequestException, requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
    print(str(e))
except Exception as e:
    print("Exceção")

html = res.content.decode('utf-8') 

soup =  BeautifulSoup(html, "lxml")

pag = soup.find('div', {'id': 'total'})

print(pag)

In this case the information is in an HTML snippet like this:

<div id="total" style="display: inline-block"><input type="hidden" name="totalProc" id="totalProc" value="35">35</div>

What I want to access is value, in this case 35. Capture number "35"

That's why I used "pag = soup.find('div', {'id': 'total'})". To slowly isolate just the number 35

But the content returned was just: <div id="total" style="display: inline-block"><img src="ajax-loader.gif"/></div>

Please does anyone know how to capture value content only?


It is dynamically pulled from another XHR call you can find in the network tab

import requests
from bs4 import BeautifulSoup as bs

r = requests.get('https://portal.stf.jus.br/processos/totalProcessosPartes.asp?termo=AECIO%20NEVES%20DA%20CUNHA&total=0')
soup = bs(r.content, 'lxml')
print(soup.select_one('#totalProc')['value'])

With regex

import requests, re

r = requests.get('https://portal.stf.jus.br/processos/totalProcessosPartes.asp?termo=AECIO%20NEVES%20DA%20CUNHA&total=0')
soup = bs(r.content, 'lxml')
print(re.search('value=(\d+)',r.text).groups(0)[0])

Get value from hidden field using jQuery, I have a <input type="hidden" value="" id='h_v' class='h_v'> Using jQuery I want to alert the user to this value . I am using var hv = $('#h_v).text();  One of the most common uses for hidden inputs is to keep track of what database record needs to be updated when an edit form is submitted. A typical workflow looks like this: User decides to edit some content they have control over, such as a blog post, or a product entry. They get started by pressing the edit button.


I'm not sure if this is a standard solution, but I personally like using regexes to isolate values from my BeautifulSoup results since they can help capture any kind of pattern. For example, in your case, if you decide to use regex your code could look like:

soup =  str(BeautifulSoup(html, "lxml"))

import regex
pag = regex.findall(r'(?<=value=")\d+', soup)

print(pag[0])

You can verify that the regex returns the content in value here.

HTML input type="hidden", Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  Get the value of the value attribute of a hidden input field: var x = document.getElementById("myInput").value; Try it Yourself ».


As I was explaining in the comments, browser automation can be a very quick solution to this issue. The first thing thing you should do is installing Google Chrome on your computer if you haven't got it already. To be fair it could work with any browser, but then I wouldn't be sure on how to set up the code properly, as I have never done it before. Secondly, you must download a tool called "chrome webdriver". You can find it here. Once downloaded, extract the file and put it in the same directory of your python script, which should be the following:

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time

ch = Options()
ch.add_argument("--disable-extensions")
ch.add_argument("--disable-gpu")
ch.add_argument("--headless")

browser = webdriver.Chrome(options = ch)
page = browser.get("https://portal.stf.jus.br/processos/listarPartes.asp?termo=AECIO%20NEVES%20DA%20CUNHA")
time.sleep(1)
pag = browser.find_element_by_id('totalProc')

print(pag.get_attribute('value'))
browser.quit()

Before executing it, don't forget to do pip install selenium in your terminal in order to install the actual selenium module. The script takes about 10-20 seconds to run, but it should work perfectly fine. Let me know if you have any trouble with it, but you definitely shouldn't.

<input type="hidden">, In the <input> element with the type=”hidden”, the change() method of jQuery is not automatically triggered. The change() method is only triggered automatically​  You get the value of a hidden input the same way you get any other input. – Barmar May 27 '15 at 17:28 yes but what i use re.findall or re.search and how writing true pattern – IBRA May 27 '15 at 17:35


How to detect value change on hidden input field in JQuery , Inserting the <input type='hidden'> can also be done using jQuery. The append() and appendTo() inbuilt function can be used to add the hidden form element  Disallows the user from editing the value of the input. placeholder: Specifies placeholder text in a text-based input. pattern: Specifies a regular expression against which to validate the value of the input. multiple: Allows the user to enter multiple values into a file upload or email input. min: Specifies a minimum value for number and date


How to create hidden form element on the fly using jQuery , Your input has an apex styleClass in the markup, but is an HTML input. Change this: <input type="hidden" value="{!c. I have a cloud page A that has Javascript and another cloud page B which has HTML, AMPscript and the cloud page A is called in cloud page B as src (). featureData has value of the id selected. var


Getting value of hidden input to jQuery, bind(), but still cannot get it to work properly. Anyone have any idea on how to get the value of the hidden input fields accessible after loading? This is working monkey56657. And I am really clueless here why in my case the hidden value is not coming. There's nothing wrong apparently, as on removing the hidden the value is getting submitted