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 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 |