Skip to content

Instantly share code, notes, and snippets.

@rizkyramadhan21
Last active June 23, 2018 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizkyramadhan21/8a785f2bfd5f2517867ac2a123c5128d to your computer and use it in GitHub Desktop.
Save rizkyramadhan21/8a785f2bfd5f2517867ac2a123c5128d to your computer and use it in GitHub Desktop.
#-*- 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