Created
October 29, 2014 15:27
-
-
Save perfectfoolish/c8e400c5315ff6a2cf83 to your computer and use it in GitHub Desktop.
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
require 'socket' | |
require 'nokogiri' | |
host = 'www.so.com' | |
port = 80 | |
path = "http://www.so.com/s?psid=aa1636dc9ced822ddb741bd94af183fc&q=%E8%89%BA%E9%BE%99&pq=%E8%89%BA%E9%BE%99&src=srp&fr=360sou_newhome" | |
request = "GET #{path} HTTP/1.0\r\n\r\n" | |
socket = TCPSocket.open(host, port) | |
socket.print(request) | |
response = socket.read | |
headers, body = response.split("\r\n\r\n",2) | |
#print body | |
doc= Nokogiri::HTML(body) | |
str=[] | |
WEntry=doc.at(".mod-relation").css('a').each do |t| | |
str << t | |
puts t.text | |
end | |
puts str.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment