nulltron
nulltron

Reputation: 646

Getting HTML Input Field value with Beautiful Soup 4

Here is my function:

def fetchIframe(vid_url):
    r = requests.get(vid_url)
    soup = BeautifulSoup(r.content)
    iframe_link = soup.find("input", {"id": "mediaEmbedCodeInput", "type": "text"}).get(['value'])

return iframe_link

The vid_url is valid, I've begun testing in the python console and I keep getting this error when I run the above function. I haven't found much documentation relating to this. I must be looking in the wrong places and asking the wrong question.

Here is the error:

iframe_link = soup.find('input', {'name':'media_embed_code'}).get('value')
AttributeError: 'NoneType' object has no attribute 'get'

And I've tried to remedy the situation by using the methods of value display from this SO post here.

I feel I'm over-complicating my issue but at the moment I can't see a way to resolve this. I realize that my iframe_link object has a NoneType but why is this?

Upvotes: 0

Views: 557

Answers (1)

nulltron
nulltron

Reputation: 646

The error actually occurred due to a link generation mix-up, thanks to @user2954587 to remind me to check the soup!

Upvotes: 1

Related Questions