启动此代码时,我无法保存在网站上找到的文件。我得到一个错误“AttributeError模块'string'没有属性'lstrip'” 我用“string.lstpri”解决不了问题,帮我找错了吗
from bs4 import BeautifulSoup
import mechanize
import time
import urllib.request
import string
start = "http://www.irrelevantcheetah.com/browserimages.html"# test website
filetype = input("What file type are you looking for?\n")
br = mechanize.Browser()
r = br.open(start)
html = r.read()
soup = BeautifulSoup(html, "html5lib")
for link in soup.find_all('a'):
linkText = str(link)
fileName = str(link.get('href'))
if filetype in fileName:
image = urllib.request.URLopener()
linkGet = "http://www.irrelevantcheetah.com" + fileName
filesave = string.lstrip(fileName, '/')
image.retrieve(linkGet, filesave)
Andrej Kesely gave the solution in a comment:
相关问题 更多 >
编程相关推荐