This file contains hidden or 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
| from urllib import request | |
| import xml.etree.ElementTree as ET | |
| url = 'http://python-data.dr-chuck.net/comments_24966.xml' | |
| print ("Retrieving", url) | |
| html = request.urlopen(url) | |
| data = html.read() | |
| print("Retrieved",len(data),"characters") | |
| tree = ET.fromstring(data) |
This file contains hidden or 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
| 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" |
This file contains hidden or 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
| #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]) |
This file contains hidden or 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 socket | |
| mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| mysock.connect(('data.pr4e.org', 80)) | |
| cmd = 'GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n'.encode() | |
| mysock.send(cmd) | |
| while True: | |
| data = mysock.recv(512) | |
| if (len(data) < 1): |
This file contains hidden or 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 re | |
| hand = open("regex_sum_24962.txt") | |
| x=list() | |
| for line in hand: | |
| y = re.findall('[0-9]+',line) | |
| x = x+y | |
| sum=0 | |
| for z in x: |
This file contains hidden or 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
| name = raw_input("Enter file:") | |
| if len(name) < 1 : name = "mbox-short.txt" | |
| hand = open(name) | |
| hours = dict() | |
| for line in hand: | |
| if line.startswith("From "): | |
| hour = line.split()[5].split(':')[0] | |
| hours[hour] = hours.get(hour, 0) + 1 |
This file contains hidden or 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
| fname = input("Enter file:") | |
| if len(fname) < 1 : name = "mbox-short.txt" | |
| hand = open(fname) | |
| lst = list() | |
| for line in hand: | |
| if not line.startswith("From:"): continue | |
| line = line.split() | |
| lst.append(line[1]) |
This file contains hidden or 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
| fhand = open("mbox-short.txt") | |
| count = 0 | |
| for line in fhand: | |
| line = line.rstrip() | |
| if line == "": continue | |
| words = line.split() | |
| if words[0] !="From": continue | |
| print(words[1]) |
This file contains hidden or 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
| fhand = open("romeo.txt") | |
| lst = list() | |
| for line in fhand: | |
| line = line.rstrip() | |
| line = line.split() | |
| for i in line: | |
| if i not in lst: | |
| lst.append(i) |
This file contains hidden or 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
| # Use the file name mbox-short.txt as the file name | |
| fname = input("Enter file name: ") | |
| fhand = open(fname) | |
| count = 0 | |
| for line in fhand: | |
| if line.startswith("X-DSPAM-Confidence:") : | |
| count = count + 1 | |
| total = 0 |
NewerOlder