python synonim_scraping.py baik OR python synonim_scraping.py tampan
Created
May 17, 2017 23:26
-
-
Save undefinedzain/c10716e1813d292690a6fafb661e66a5 to your computer and use it in GitHub Desktop.
Get synonim of a word . scraping . :D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment