New to Python, have a simple, situational question:
Trying to use BeautifulSoup to parse a series of pages.
from bs4 import BeautifulSoup
import urllib.request
BeautifulSoup(urllib.request.urlopen('http://bit.ly/'))
Traceback ...
html.parser.HTMLParseError: expected name token at '<!=KN\x01...
Working on Windows 7 64-bit with Python 3.2.
Do I need Mechanize? (which would entail Python 2.X)
If that URL is correct, you're asking why an HTML parser throws an error parsing an MP3 file. I believe the answer to this to be self-evident...
If you were trying to download that MP3, you could do something like this:
import urllib2
BLOCK_SIZE = 16 * 1024
req = urllib2.urlopen("http://bit.ly/xg7enD")
#Make sure to write as a binary file
fp = open("someMP3.mp3", 'wb')
try:
while True:
data = req.read(BLOCK_SIZE)
if not data: break
fp.write(data)
finally:
fp.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With