Python3.4.0,TypeError: Type str doesn't support the buffer API
求助,程序出现问题:#-*-coding:utf-8-*-importurllib.requestdefget_page(url):returnurllib.reques...
求助,程序出现问题:
#-*-coding:utf-8-*-
import urllib.request
def get_page(url):
return urllib.request.urlopen(url).read()
def get_next_target(page):
start_link=page.find('<a href=')
if start_link==-1:
return None,0
start_quote=page.find('"',start_link)
end_quote=page.find('"',start_quote+1)
url=page[start_quote+1:end_quote]
return url,end_quote
def get_all_links(page):
url_list=[]
while True:
url,endpos=get_next_target(page)
if url:
url_list.append(url)
page=page[endpos:]
else:
break
return url_list
错误提示为:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
get_all_links(get_page('http://www.google.cn'))
File "D:\New Folder\test\get_all_links.py", line 19, in get_all_links
url,endpos=get_next_target(page)
File "D:\New Folder\test\get_all_links.py", line 8, in get_next_target
start_link=page.find('<a href=')
TypeError: Type str doesn't support the buffer API 展开
#-*-coding:utf-8-*-
import urllib.request
def get_page(url):
return urllib.request.urlopen(url).read()
def get_next_target(page):
start_link=page.find('<a href=')
if start_link==-1:
return None,0
start_quote=page.find('"',start_link)
end_quote=page.find('"',start_quote+1)
url=page[start_quote+1:end_quote]
return url,end_quote
def get_all_links(page):
url_list=[]
while True:
url,endpos=get_next_target(page)
if url:
url_list.append(url)
page=page[endpos:]
else:
break
return url_list
错误提示为:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
get_all_links(get_page('http://www.google.cn'))
File "D:\New Folder\test\get_all_links.py", line 19, in get_all_links
url,endpos=get_next_target(page)
File "D:\New Folder\test\get_all_links.py", line 8, in get_next_target
start_link=page.find('<a href=')
TypeError: Type str doesn't support the buffer API 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询