Skip to content

Instantly share code, notes, and snippets.

View fermartz10's full-sized avatar

Fernando Martinez fermartz10

View GitHub Profile
@MichelleDalalJian
MichelleDalalJian / py4e_ex_12_02
Created November 24, 2017 16:04
Following Links in Python: The program will use urllib to read the HTML from the data files below, extract the href= vaues from the anchor tags, scan for a tag that is in a particular position relative to the first name in the list, follow that link and repeat the process a number of times and report the last name you find.
from bs4 import BeautifulSoup
import urllib.request, urllib.parse, urllib.error
import ssl
import re
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = "http://py4e-data.dr-chuck.net/known_by_Bryce.html"
@MichelleDalalJian
MichelleDalalJian / py4e_ex_12_01
Last active November 18, 2023 00:44
Scraping Numbers from HTML using BeautifulSoup. The program will use urllib to read the HTML from the data files below, and parse the data, extracting numbers and compute the sum of the numbers in the file.
#Actual data: http://py4e-data.dr-chuck.net/comments_24964.html (Sum ends with 73)
from urllib import request
from bs4 import BeautifulSoup
html=request.urlopen('http://python-data.dr-chuck.net/comments_24964.html').read()
soup = BeautifulSoup(html)
tags=soup('span')
sum=0
for tag in tags:
sum=sum+int(tag.contents[0])
@manichabba
manichabba / Sqlite.py
Created August 23, 2016 20:45
Counting Organizations This application will read the mailbox data (mbox.txt) count up the number email messages per organization (i.e. domain name of the email address) using a database with the following schema to maintain the counts.
import re
import sqlite3
conn = sqlite3.connect('emaildb.sqlite')
cur = conn.cursor()
cur.execute('''
DROP TABLE IF EXISTS Counts''')
@manichabba
manichabba / geoJSON.py
Created August 20, 2016 03:21
=====Calling a JSON API=====The program will prompt for a location, contact a web service and retrieve JSON for the web service and parse that data, and retrieve the first place_id from the JSON. A place ID is a textual identifier that uniquely identifies a place as within Google Maps.
import urllib
import json
serviceurl = 'http://python-data.dr-chuck.net/geojson?'
while True:
address = raw_input('Enter location: ')
if len(address) < 1 : break
@manichabba
manichabba / jsonscraping.py
Created August 20, 2016 01:17
====Extracting Data from JSON: ==== The program will prompt for a URL, read the JSON data from that URL using urllib and then parse and extract the comment counts from the JSON data, compute the sum of the numbers in the file and provide the sum.
import urllib #importing urllib
import json #importing json
#requesting a json file url
url = raw_input("Enter the URL:")
#load json file as list -info
info = json.loads(urllib.urlopen(url).read())
x = 0
#loop through each item in list comments