Парсер youtube подправить код
Парсер прекрасно раньше работал. Сейчас стал выдавать исключение:
>>> Python 3.8.0a1 (tags/v3.8.0a1:e75eeb00b5, Feb 3 2019, 19:46:54) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> Warning (from warnings module):
File "C:\Users\Александр\Desktop\Парсер youtube\parsery_youtube.py", line 9
match = re.findall('(\?v\=(.+?)\")+.*(title="(.+?)\")', doc)
SyntaxWarning: invalid escape sequence \?
Вот код самого парсера:
# -*- coding: utf-8 -*-
import urllib.parse
import urllib.request
import re, os, sys
def findyoutube(x):
mas=[]
sq='http://www.youtube.com/results?search_query='+urllib.parse.quote(x)
doc = urllib.request.urlopen(sq).read().decode('utf8',errors='ignore')
match = re.findall('(\?v\=(.+?)\")+.*(title="(.+?)\")', doc)
if not(match is None):
for ii in match:
if(len(ii)<25):
mas.append(ii[3] + '\n*replace*' + ii[1] + '\n')
mas=dict(zip(mas,mas)).values()
mas2=[]
for y in mas: mas2.append(f'{y}'.replace('*replace*', 'http://www.youtube.com/watch?v='))
return mas2
print(findyoutube('болонская+удочка°'))
with open('output.txt', 'w', encoding='utf8') as output:
for i in findyoutube('болонская+удочка'):
output.write(i+'\n')