When running my codes, I get this error
UnicodeEncodeError: 'ascii' codec can't encode character '\u0303' in position 71: ordinal not in range(128)
This is my whole codes,
from urllib.request import urlopen as uReq
from urllib.request import urlretrieve as uRet
from bs4 import BeautifulSoup as soup
import urllib
for x in range(143, 608):
myUrl = "example.com/" + str(x)
try:
uClient = uReq(myUrl)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
container = page_soup.findAll("div", {"id": "videoPostContent"})
img_container = container[0].findAll("img")
images = img_container[0].findAll("img")
imgCounter = 0
if len(images) == "":
for image in images:
print('Downloading image from ' + image['src'] + '...')
imgCounter += 1
uRet(image['src'], 'pictures/' + str(x) + '.jpg')
else:
for image in img_container:
print('Downloading image from ' + image['src'] + '...')
imgCounter += 1
uRet(image['src'], 'pictures/' + str(x) + '_' + str(imgCounter) + '.jpg')
except urllib.error.HTTPError:
continue
Tried Solutions:
I tried adding .encode/decode('utf-8') and .text.encode/decode('utf-8') to page_soup but it gives this errors.
AttributeError: 'str' / 'bytes' object has no attribute 'findAll' or
findAll. What line is throwing the error? - TheF1rstPancakeencodeany string before you put it in uRet. Likelyimages['src'].encode('utf-8'). - TheF1rstPancake.encode('utf-8)inimages['src']but it gives me:TypeError: cannot use a string pattern on a bytes-like object- Axis