問題描述: ValueError:unsupported format character 'j' (0x6a) at index 21
即倒數第6行 .jpg j出什麼問題了? ? ?
import urllib.request
from bs4 import BeautifulSoup
def get_content(url):
html = urllib.request.urlopen(url)
content = html.read().decode('utf-8')
html.close()
return content
def get_image(info):
soup = BeautifulSoup(info,"lxml")
all_image = soup.find_all('img',class_="BDE_Image") #一个一个保存
x=1
for image in all_image:
print(image)
urllib.request.urlretrieve(image['src'],"C:\Users\jack Lee\s%.jpg" %(x))
x+=1
url = "https://tieba.baidu.com/p/2218566379"
info = get_content(url)
print (info)
get_image(info)
是
%s
,而不是 s%