-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhindi_quotes.py
More file actions
30 lines (24 loc) · 859 Bytes
/
hindi_quotes.py
File metadata and controls
30 lines (24 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import urllib, requests
from bs4 import BeautifulSoup
def get_hindi_quotes(text):
print("fetching_q_hindi....")
text = text.strip().replace(" ", "+")
query_url = "https://www.shayarism.com/?s={}".format(text)
try:
html = requests.get(query_url)
soup = BeautifulSoup(html.text, "html.parser")
results = soup.select("div[class='post-entry']")
if len(results) == 0:
return "No results found :(\nSearch for something else :)"
response = ""
count = 0
for result in results:
response += result.getText()
count += 1
if count == 5:
break
response += "\n........\n"
response = urllib.parse.quote_plus(response)
return response
except Exception as _:
return "Error Occurred!"