Reputation: 39
This is the code I want to scrape
<li id="shortlink">
<strong>Short link:</strong>
<input id="short-link-input" type="text" value="http://tnydu.biz/DfBCAEk" onclick="dbzglobal_event_adapter();">
</li>
The script i am using is this:
shortlink=soup.select("#short-link-input value")
print shortlink
but it gives [] output and I cannot extract the link for it. Available methods are find and select. can someone help please
Upvotes: 0
Views: 181
Reputation: 886
Try this
elem = soup.find('input',{'id':'short-link-input'})
print elem.get('value')
Upvotes: 2
Reputation: 1882
Try this:
shortlink=soup.select("#short-link-input")[0]['value']
select
-method returns a list of elements. To get the value of an attribute, you have to call its get
-method or use the attribute's name as key-index
Upvotes: 0