当我在没有面向对象编程的情况下使用这段代码时,它是有效的。你知道吗
但是当我想在类print(link['href])
中使用它时,会出现以下错误:
TypeError: string indices must be integers
有什么问题?你知道吗
class Link(object):
def get_linkblock(self,url):
import httplib2
from bs4 import BeautifulSoup as bs
from bs4 import SoupStrainer
self.url = url
print(self.url)
self.http = httplib2.Http()
self.status, self.response = self.http.request(self.url)
for link in bs(self.response, "lxml", parse_only=SoupStrainer('a')):
print(link['href']) # <---- PROBLEM IS HERE
目前没有回答
相关问题 更多 >
编程相关推荐