-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 907fad9
Showing
3 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'socket' | ||
|
||
|
||
# socket = Socket.new(:INET, :STREAM ) | ||
# sockaddr = Socket.sockaddr_in(80,host) | ||
# socket.connect(sockaddr) | ||
# socketMesgReceive = socket.recv(10000) | ||
# print socketMesgReceive | ||
# print "\n" | ||
|
||
url = "http://example.org/index.html" | ||
|
||
def request(url) | ||
url = url[7..-1] | ||
|
||
host, path = url.split("/") | ||
path = "/" + path | ||
|
||
socket = TCPSocket.new(host,80) | ||
|
||
socketMesg = "GET %s HTTP/1.0\r\n" % [path] + | ||
"HOST: %s\r\n\r\n" % [host] | ||
socketMesg = socketMesg.encode("UTF-8") | ||
socketMesg = socket.send(socketMesg,0) | ||
|
||
File.write("socket_return_data.txt","") | ||
|
||
File.open("socket_return_data.txt",'w'){ | ||
|f| | ||
while line = socket.gets | ||
f.write line | ||
end | ||
} | ||
|
||
webPage = File.open("socket_return_data.txt",'r') | ||
|
||
firstLine = webPage.readline | ||
flVersion, flStatus, flExplanation = firstLine.split(" ",3) #em python era para ser 2 | ||
|
||
|
||
headers = {} | ||
while 1 | ||
line = webPage.readline | ||
if line == "\r\n" | ||
break | ||
end | ||
header, value = line.split(":",2) | ||
headers[header.downcase] = value.strip | ||
end | ||
|
||
body = webPage.read | ||
webPage.close | ||
|
||
return headers, body | ||
end | ||
|
||
File.write("test.txt", " ") | ||
def show(body) | ||
|
||
testFile = File.open("test.txt", 'a') | ||
|
||
in_angle = false | ||
body.each_char { | ||
|content| | ||
if content == "<" | ||
in_angle = true | ||
elsif content == ">" | ||
in_angle = false | ||
elsif not in_angle | ||
print content | ||
testFile.write content | ||
end | ||
} | ||
testFile.close | ||
end | ||
|
||
def load(url) | ||
headers, body = request(url) | ||
show(body) | ||
end | ||
|
||
|
||
load(url) | ||
|
||
|
||
|
||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
HTTP/1.0 200 OK | ||
Accept-Ranges: bytes | ||
Age: 595370 | ||
Cache-Control: max-age=604800 | ||
Content-Type: text/html; charset=UTF-8 | ||
Date: Thu, 23 Feb 2023 19:59:03 GMT | ||
Etag: "3147526947" | ||
Expires: Thu, 02 Mar 2023 19:59:03 GMT | ||
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT | ||
Server: ECS (mic/9AF5) | ||
Vary: Accept-Encoding | ||
X-Cache: HIT | ||
Content-Length: 1256 | ||
Connection: close | ||
|
||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Example Domain</title> | ||
|
||
<meta charset="utf-8" /> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<style type="text/css"> | ||
body { | ||
background-color: #f0f0f2; | ||
margin: 0; | ||
padding: 0; | ||
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
|
||
} | ||
div { | ||
width: 600px; | ||
margin: 5em auto; | ||
padding: 2em; | ||
background-color: #fdfdff; | ||
border-radius: 0.5em; | ||
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02); | ||
} | ||
a:link, a:visited { | ||
color: #38488f; | ||
text-decoration: none; | ||
} | ||
@media (max-width: 700px) { | ||
div { | ||
margin: 0 auto; | ||
width: auto; | ||
} | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div> | ||
<h1>Example Domain</h1> | ||
<p>This domain is for use in illustrative examples in documents. You may use this | ||
domain in literature without prior coordination or asking for permission.</p> | ||
<p><a href="https://www.iana.org/domains/example">More information...</a></p> | ||
</div> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
|
||
|
||
Example Domain | ||
|
||
|
||
|
||
|
||
|
||
body { | ||
background-color: #f0f0f2; | ||
margin: 0; | ||
padding: 0; | ||
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
|
||
} | ||
div { | ||
width: 600px; | ||
margin: 5em auto; | ||
padding: 2em; | ||
background-color: #fdfdff; | ||
border-radius: 0.5em; | ||
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02); | ||
} | ||
a:link, a:visited { | ||
color: #38488f; | ||
text-decoration: none; | ||
} | ||
@media (max-width: 700px) { | ||
div { | ||
margin: 0 auto; | ||
width: auto; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
Example Domain | ||
This domain is for use in illustrative examples in documents. You may use this | ||
domain in literature without prior coordination or asking for permission. | ||
More information... | ||
|
||
|
||
|