Skip to content

Instantly share code, notes, and snippets.


gouneken/ Secret

Created Jun 24, 2022
What would you like to do?
def search(request):
if request.method == 'POST':
search = request.POST['search']
url = ''+search
res = requests.get(url)
soup = bs(res.text, 'lxml')
result_listings = soup.find_all('div', {'class': 'PartialSearchResults-item'})
final_result = []
for result in result_listings:
result_title = result.find(class_='PartialSearchResults-item-title').text
result_url = result.find('a').get('href')
result_desc = result.find(class_='PartialSearchResults-item-abstract').text
next_page = result.find('a').get('PartialWebPagination-next ')
if next_page:
url = next_page.attrib.get('href')
return requests.get(url)
final_result.append((result_title, result_url, result_desc))
context = {
'final_result': final_result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment