Skip to content

Instantly share code, notes, and snippets.

@undefinedzain
Created May 17, 2017 23:26
Show Gist options
  • Save undefinedzain/c10716e1813d292690a6fafb661e66a5 to your computer and use it in GitHub Desktop.
Save undefinedzain/c10716e1813d292690a6fafb661e66a5 to your computer and use it in GitHub Desktop.
Get synonim of a word . scraping . :D
import requests
from bs4 import BeautifulSoup
import sys
if len(sys.argv) == 1:
print ('Please input at least a word, i.e python scraping.py bisa')
else:
kata = sys.argv[1]
headers = {'User-Agent': 'Mozilla/5.0'}
payload = {'q':kata}
session = requests.Session()
resp = session.post('http://www.persamaankata.com/search.php',headers=headers,data=payload)
html_element = BeautifulSoup(resp.content,'lxml')
if len(html_element.find_all('ul')) > 0:
all_ul = html_element.find_all('ul')[0] # Sinonim aja ul[1] isinya antonim
all_ul.find_all('div',{'class' : 'word_thesaurus'})
a = all_ul.find_all('a')
synonim_array = []
for sinonim in a:
print(sinonim).text
else:
print('Please input right words')

For usage just run command below

python synonim_scraping.py baik OR python synonim_scraping.py tampan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment