Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
👌 Changed imports for both Python 2 & 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Aug 7, 2020
1 parent bda9d4c commit 1bfbbb3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 12 additions & 3 deletions youtubesearchpython/__requesthandler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import urllib
import sys

#########python2#########
if sys.version_info < (2, 8):
from urllib import urlencode, urlopen

#########python3#########
else:
from urllib.request import urlopen
from urllib.parse import urlencode


class requesthandler:

def request(self):

try:
query = urllib.urlencode({
query = urlencode({
"search_query": self.keyword,
"page": self.offset,
"sp": self.searchPreferences
Expand All @@ -15,7 +24,7 @@ def request(self):

#########Making Network Request#########

response = urllib.urlopen(request).read()
response = urlopen(request).read()

self.page = response.decode('utf_8')

Expand Down
14 changes: 12 additions & 2 deletions youtubesearchpython/videos__pagehandler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import HTMLParser
import sys

#########python2#########
if sys.version_info < (2, 8):
import HTMLParser

#########python3#########
else:
import html


class pagehandler:
Expand All @@ -25,7 +33,9 @@ def pageResponseHandler(self):

self.pageSource = self.page.split()

html = HTMLParser.HTMLParser()
#########python2#########
if sys.version_info < (2, 8):
html = HTMLParser.HTMLParser()

for index in range(0, len(self.pageSource) - 1, 1):

Expand Down

0 comments on commit 1bfbbb3

Please sign in to comment.