search

Home  >  Q&A  >  body text

Newbie - Python crawler problem help

Problem description: ValueError: unsupported format character 'j' (0x6a) at index 21
That is, the 6th line from the bottom.jpg What's wrong with 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)

phpcn_u1582phpcn_u15822729 days ago923

reply all(1)I'll reply

  • 迷茫

    迷茫2017-07-05 10:37:09

    is %s, not s%

    reply
    0
  • Cancelreply