如何用luasocket和代理获取指定URL页面,长尾词疑问?
- 内容介绍
- 文章标签
- 相关推荐
本文共计318个文字,预计阅读时间需要2分钟。
以下是对原文的简化
使用local socket库,通过指定代理连接到http://example.com。代码如下:local socket=require(socket.http)local r, c, h=socket.request({url=http://example.com, proxy=my proxy and port here})for i, v in pairs(c) do print(i, v)end
到目前为止,我有以下内容:local socket = require "socket.example.com/", proxy="<my proxy and port here>"} for i,v in pairs( c ) do print( i, v ) end
这给了我一个如下输出:
connection close content-type text/html; charset=UTF-8 location www.iana.org/domains/example/ vary Accept-Encoding date Tue, 24 Apr 2012 21:43:19 GMT last-modified Wed, 09 Feb 2011 17:13:15 GMT transfer-encoding chunked server Apache/2.2.3 (CentOS)
这意味着连接建立得非常完美.现在,我想使用这个socket.example.com/", sink = ltn12.sink.table(result_table), proxy="<my proxy and port here>" } -- Join the chunks together into a string: local result = table.concat(result_table); -- Hacky solution to extract the title: local title = result:match("<[Tt][Ii][Tt][Ll][Ee]>([^<]*)<"); print(title);
如果您的代理在整个应用程序中保持不变,那么更直接的解决方案是使用www.youtube.com/watch?v=_eT40eV7OiI") local title = result:match("<[Tt][Ii][Tt][Ll][Ee]>([^<]*)<"); print(title);
输出:
Flanders and Swann - A song of the weather - YouTube
本文共计318个文字,预计阅读时间需要2分钟。
以下是对原文的简化
使用local socket库,通过指定代理连接到http://example.com。代码如下:local socket=require(socket.http)local r, c, h=socket.request({url=http://example.com, proxy=my proxy and port here})for i, v in pairs(c) do print(i, v)end
到目前为止,我有以下内容:local socket = require "socket.example.com/", proxy="<my proxy and port here>"} for i,v in pairs( c ) do print( i, v ) end
这给了我一个如下输出:
connection close content-type text/html; charset=UTF-8 location www.iana.org/domains/example/ vary Accept-Encoding date Tue, 24 Apr 2012 21:43:19 GMT last-modified Wed, 09 Feb 2011 17:13:15 GMT transfer-encoding chunked server Apache/2.2.3 (CentOS)
这意味着连接建立得非常完美.现在,我想使用这个socket.example.com/", sink = ltn12.sink.table(result_table), proxy="<my proxy and port here>" } -- Join the chunks together into a string: local result = table.concat(result_table); -- Hacky solution to extract the title: local title = result:match("<[Tt][Ii][Tt][Ll][Ee]>([^<]*)<"); print(title);
如果您的代理在整个应用程序中保持不变,那么更直接的解决方案是使用www.youtube.com/watch?v=_eT40eV7OiI") local title = result:match("<[Tt][Ii][Tt][Ll][Ee]>([^<]*)<"); print(title);
输出:
Flanders and Swann - A song of the weather - YouTube

