MetalMichael
01-09-2011, 12:51 AM
Okay, well I'm pretty new to python. I can open a url, but when it comes to doing anything with it, I keep getting errors. Pretty sure I'm doing it wrong.
So I've imported urllib.request, and do:
youtubesearch = urllib.request.urlopen('http://www.youtube.com/results?search_query=' + query)
this opening works, but then when I want to do something with it, for example, perform regex operations, I the error TypeError: expected string or buffer.
code used:
youtubere = re.compile('watch\?v=([^\"&]+)"\stitle[\s\S]{0,400}?<b>' + query, re.I)
youtubesearch = urllib.request.urlopen('http://www.youtube.com/results?search_query=' + query)
youtubelink = re.search(youtubere, youtubesearch)
Full error:
(other traces)
File "C:\Python31\lib\re.py", line 157, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer
Edit: Note, using python 3.1
Just for note... this is the sort of thing that if I were using php, I would do
$page = file_get_contents($Url);
preg_match('/regex\sand\sstuff/i',$page,$output)
So I've imported urllib.request, and do:
youtubesearch = urllib.request.urlopen('http://www.youtube.com/results?search_query=' + query)
this opening works, but then when I want to do something with it, for example, perform regex operations, I the error TypeError: expected string or buffer.
code used:
youtubere = re.compile('watch\?v=([^\"&]+)"\stitle[\s\S]{0,400}?<b>' + query, re.I)
youtubesearch = urllib.request.urlopen('http://www.youtube.com/results?search_query=' + query)
youtubelink = re.search(youtubere, youtubesearch)
Full error:
(other traces)
File "C:\Python31\lib\re.py", line 157, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer
Edit: Note, using python 3.1
Just for note... this is the sort of thing that if I were using php, I would do
$page = file_get_contents($Url);
preg_match('/regex\sand\sstuff/i',$page,$output)