Advertisement
WILDAN_IZZUDIN

[PY] JAGOKATA

Apr 21st, 2024
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import requests
  2. import json
  3. from bs4 import BeautifulSoup
  4.  
  5. class Jagokata:
  6.      
  7.    def search(q):
  8.      
  9.       req = requests.get('https://jagokata.com/kata-bijak/kata-' + q.replace(' ', '-') + '.html')
  10.       soup = BeautifulSoup(req.content, 'html.parser')
  11.       ul = soup.find('ul', id='citatenrijen')
  12.       data = []
  13.       for li in ul.find_all('li'):
  14.          res = {
  15.             'content': li.find('q').text,
  16.             'by': li.find('img')['alt']
  17.          }
  18.          data.append(res)
  19.    
  20.       result = json.dumps(data, indent=3)
  21.       if len(data) < 1: return json.dumps({
  22.          'status': false
  23.       }, indent=3)
  24.       return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement