Zach C
Zach C

Reputation: 91

How to get form action element using beautiful soup?

I am trying to grab a form action using beautiful soup enter image description here

I have tried print(soup.find('form').find_all('action')) but that doesnt work. Wondering if there is an easy way. ( I am trying to get the rest of the string after ?dwcont= )

Upvotes: 1

Views: 635

Answers (2)

talhoid
talhoid

Reputation: 71

action = soup.find('form').get('action')
print(action.split("?dwcont=",1)[1])

References

How to get a string after a specific substring?

Getting form "action" from BeautifulSoup result

Upvotes: 0

Barmar
Barmar

Reputation: 780798

action is an attribute, .find_all() is for finding elements. Use ['action'].

print(soup.find('form')['action'])

Upvotes: 1

Related Questions