Last active
June 23, 2018 09:36
-
-
Save rizkyramadhan21/8a785f2bfd5f2517867ac2a123c5128d to your computer and use it in GitHub Desktop.
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
#-*- coding: utf-8 -*- | |
#--------------------------------------- | |
#!/usr/bin/python | |
#--------------------------------------- | |
# Scrape wikipedia Table | |
# Rizky | https://www.wadagizig.com | |
#--------------------------------------- | |
import urllib2 | |
from bs4 import BeautifulSoup | |
def wikiTable(): | |
# Spesifikasikan alamat url: | |
alamatURL = "https://en.wikipedia.org/wiki/Comparison_of_programming_languages" | |
# Mengakses alamatURL | |
page = urllib2.urlopen(alamatURL) | |
# Memparse alamat diatas menggunakan parser: "html.parser" | |
soup = BeautifulSoup(page, 'lxml') | |
# Menemukan tabel yang menjadi target | |
table = soup.find('table', id="Expressiveness") | |
# Menemukan table row dari tabel target: | |
table_rows = table.find_all('tr') | |
# Menemukan td dari setiap table rows: | |
for tr in table_rows: | |
td = tr.find_all('td') | |
row = [i.text for i in td] | |
print row | |
wikiTable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment