def select(self):
search = self.search
sess = self.login()
print('Loading search page...')
for c in range(10):
sess.visit(self.SEARCH_URI.format(keywords=quote(search)))
sleep(20 + c)
sess.interact
self.client = sess
if 'results-list' in sess.body():
break
soup = BeautifulSoup(sess.body(), 'lxml')
ul = soup.find('ul', {'class', 'results-list'})
lis = ul.findAll('li')
links = dict()
loop = 5 if len(lis) > 5 else len(lis)
for idx in range(loop):
aux = lis[idx].find('div', {'class':'search-result__info'})
link = aux.find('a', {'class':'search-result__result-link'})
link = link.get('href') if link else '??'
name = aux.find('h3', {'class':'search-result__title'})
name = name.text if name else '??'
desc = aux.find('p', {'class':'subline-level-1'})
desc = desc.text if desc else '??'
if str(idx) not in links.keys():
links[str(idx)] = dict()
links[str(idx)].update(dict(link=link, name=name, desc=desc))
choice = self.printlinks(links)
return choice
评论列表
文章目录