We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,011 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Need some help parsing with BeautifulSoup!

I'm trying to write a script that will search a page for mp3 files, and download the first one. All is fine, but when I'm finding the links the first two are not mp3 files. At the moment I'm doing:

for link in page.findAll('a')[:3]:
   f.write(link.get('href'))

This finds the first 3 results, the third of which is the first mp3 file on the page. My question is, instead of finding the first three links, how can i find JUST the third? I need to do this so I can write it to a file and let my downloader pick it up.

Thanks in advance, Tom.

2
Contributors
2
Replies
5 Hours
Discussion Span
9 Months Ago
Last Updated
3
Views
Question
Answered
satnav_8
Newbie Poster
7 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

page.findAll('a')[2].get('href')

pyTony
pyMod
Moderator
6,305 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26

Thanks Tony, works a treat.

satnav_8
Newbie Poster
7 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 9 Months Ago by pyTony

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0788 seconds using 2.7MB