I wish to extract all forms from a given website using Python3 and BeautifulSoup.
Here is an example that does this, but fails to pick up all forms:
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = 'https://www.qantas.com/au/en.html'
data = urlopen(url)
parser = BeautifulSoup(data, 'html.parser')
forms = parser.find_all('form')
for form in forms:
print(form)
print('\n\n')
If you run the code and visit the URL, you will notice that the Book a trip
form is not scraped by the parser.
The above code only picks up three forms, whereas in Chrome's Developers tools > elements
page shows 13 <form>
elements. But if I view the page source (Ctrl+U
in Chrome), the source only shows the three forms that BeautifulSoup scraped.
How can I scrape all forms?