1
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 26 17:31:06 2017
@author: Pavan Vallapureddy
"""
"""
Write a program to prompt the user for the URL so it can read any web page.
You can use split('/') to break the URL into its component parts so you can
extract the host name for the socket connect call.
"""
import socket
url = input("Enter url: ")
port = int(input("Enter port: "))
urlSplit = url.split("/")
host = urlSplit[2]
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect((host, port))
cmd = "GET " + url + " HTTP/1.0\r\n\r\n".encode
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print(data.decode())
mysock.close()
Entrez url: http://data.pr4e.org/romeo.txt
Entrez le port: 80
retraçage (appel le plus récent en dernier):
Fichier "exercise1.py", ligne 17, en
cmd = "GET" + url + "HTTP/1.0 \ r \ n \ r \ n" .encode
TypeError: doit être str, pas builtin_function_or_methodretraçage lorsque vous essayez de lire les données des pages Web
qui a fonctionné. Merci pour votre aide –
@PavanVallapureddy Content de vous aider! S'il vous plaît envisager d'accepter cette réponse. Merci! – Ajax1234