原本我查找所有的div.class.profile-head信息,但有个页面没有了这一class属性,然后就报错了。我该如何跳过,然后爬取下一页呢?
我的代码如下:
def get_detail():
detail_links=detail_list()
names=[]
for detail in detail_links:
r=requests.get(detail)
soup=BeautifulSoup(r.text,'lxml')
content=soup.find('div',{'class':'profile-head'})
for name in content.find_all('h2'):
names.append(name)