Can't access HTML value using BeautifulSoup4

Viewed 37

I am trying to access the value field in on wolfram website https://www.wolframalpha.com/calculators/triple-integral-calculator

I wanted to access each of those 4 fields and copy each to a list in python. I am struggling at getting to the value.

Here is the HTML picture: enter image description here

And here is my code and what I have tried so far:

from bs4 import BeautifulSoup
import requests

URL = 'https://www.wolframalpha.com/calculators/triple-integral-calculator'
page = requests.get(URL)
print(page)

soup = BeautifulSoup(page.content, 'html.parser')

content = soup.find("div",{"class":"_3hRV6"})
label = content.find("label",{"class":""})
value = content.find("input",{"autocapitalize":"off"})
hint = value.find("id")
print(content)
print(label)
print(value)
print(hint)

any help would be appreciated it.

Thank you, Osmiqa

1 Answers

To get all 4 values from <input> into a list you can use:

import requests
from bs4 import BeautifulSoup

URL = "https://www.wolframalpha.com/calculators/triple-integral-calculator"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")

out = [inp["value"] for inp in soup.select("input")]
print(out)

Prints:

['x^2 + y^2 + z^2', 'x', 'y', 'z']
Related