В своем коде я попытался сделать так, чтобы код отображался в введенном URL. Это просто ставит плохой запрос. Это также сделано в python.
Мой код:
import socket
print("Enter a URL Below:")
x = input()
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET', x, '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(),end='')
mysock.close()
print('If it says "HTTP/1.1 200 OK" at the top, That means the connections are OK. The code is ')
Мой вывод:
Enter a URL Below:
https://www.google.com/webhp?hl=en&sa=X&ved=0ahUKEwjU8fr9oJDoAhVB7qwKHX6VB0AQPAgH
HTTP/1.1 400 Bad Request
Date: Tue, 10 Mar 2020 15:50:00 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Length: 308
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at do1.dr-chuck.com Port 80</address>
</body></html>
If it says "HTTP/1.1 200 OK" at the top, That means the connections are OK. The code is
>>>
= RESTART: C:/Users/sharm/AppData/Local/Programs/Python/Python38-32/WebBrowser.py
Enter a URL Below:
https://www.google.com/
Traceback (most recent call last):
File "C:/Users/sharm/AppData/Local/Programs/Python/Python38-32/WebBrowser.py", line 10, in <module>
mysock.send(cmd)
TypeError: a bytes-like object is required, not 'tuple'
Я просто хочу сделать веб-браузер в Python и браузеры на GitHub - это пакет, и мне это не нравится.
Дайте мне код Python 3, который это исправит.