问题真难写 发表于 2020-6-9 21:05:30

最简单的wodemo爬取代码

本帖最后由 问题真难写 于 2020-6-9 21:11 编辑

--本代码仅供学习使用,因此有很多地方比较粗糙,这是本人刚刚学会一丁丁丁丁点爬虫后研究出来的小玩意,如有不足之处,请指正。
require"import"
import "android.widget.ListView"
import "android.view.Gravity"
import "android.graphics.drawable.GradientDrawable$Orientation"
import "android.widget.ArrayAdapter"
import "android.widget.LinearLayout"
import "android.widget.TextView"
import "android.R$id"
import "com.androlua.Http"
l={
    ListView;
    layout_width="fill";
    layout_height="fill";
    VerticalScrollBarEnabled=false;
    dividerHeight=1;
id="list"
    };
activity.setContentView(loadlayout(l))
wz=
{
LinearLayout;--线性布局
Orientation='vertical';--布局方向
layout_width='fill';--布局宽度
layout_height='fill';--布局高度
background='';--布局背景颜色(或图片路径)
{
TextView;--文本控件
layout_width='fill';--文本宽度
layout_height='wrap';--文本高度
Gravity='center';--对齐方式
textColor='#000000';--文本颜色

textSize='20sp';--文本大小
text="";
id="ttt"
};
{
TextView;--文本控件
layout_width='fill';--文本宽度
layout_height='wrap';--文本高度
Gravity='center';--对齐方式
textColor='#000000';--文本颜色

textSize='20sp';--文本大小
text="";
id="tmt"
};
{
TextView;--文本控件
layout_width='fill';--文本宽度
layout_height='wrap';--文本高度
Gravity='center';--对齐方式
textColor='#000000';--文本颜色

textSize='20sp';--文本大小
text="";
id="pt"
};
};
data={}
adp=ArrayAdapter(activity,android.R.layout.simple_list_item_1,data)
list.setAdapter(adp)
print"尝试爬虫中"
Http.get("https://wtznx.wodemo.net/"
,nil,nil,nil,function(code,content)
    if code==200 then
con=content:match("<li>&nbsp;(.-)</ul>")
title=con:gmatch('">(.-)</a>')
link=con:gmatch("a href=(.-)>")
linkData={}
for v in title do
adp.add(v)
end
for i in link do
table.insert(linkData,i)
end
list.onItemClick=function(l,v,p,i)
url=linkData:match('"(.-)"')
Http.get(url
,nil,nil,nil,function(code,content)
tt=content:match("<title>(.-)</title>")
tm=content:match("timestamp=(.-)+0800")
time=tm:match(">(.+)")
p=content:match("<p>(.-)</p>")
activity.setContentView(loadlayout(wz))
ttt.text="您正在查看的是"..tt
tmt.text="发布时间"..time
pt.text="内容:"..p
    end
)
end
else
print"请求失败"   
      end
    end
)

问题真难写 发表于 2020-6-9 21:07:04

--本代码仅供学习使用,因此有很多地方比较粗糙,这是本人刚刚学会一丁丁丁丁点爬虫后研究出来的小玩意,如有不足之处,请指正。
require"import"
import "android.widget.ListView"
import "android.view.Gravity"
import "android.graphics.drawable.GradientDrawable$Orientation"
import "android.widget.ArrayAdapter"
import "android.widget.LinearLayout"
import "android.widget.TextView"
import "android.R$id"
import "com.androlua.Http"
l={
    ListView;
    layout_width="fill";
    layout_height="fill";
    VerticalScrollBarEnabled=false;
    dividerHeight=1;
id="list"
    };
activity.setContentView(loadlayout(l))
wz=
{
LinearLayout;--线性布局
Orientation='vertical';--布局方向
layout_width='fill';--布局宽度
layout_height='fill';--布局高度
background='';--布局背景颜色(或图片路径)
{
TextView;--文本控件
layout_width='fill';--文本宽度
layout_height='wrap';--文本高度
Gravity='center';--对齐方式
textColor='#000000';--文本颜色

textSize='20sp';--文本大小
text="";
id="ttt"
};
{
TextView;--文本控件
layout_width='fill';--文本宽度
layout_height='wrap';--文本高度
Gravity='center';--对齐方式
textColor='#000000';--文本颜色

textSize='20sp';--文本大小
text="";
id="tmt"
};
{
TextView;--文本控件
layout_width='fill';--文本宽度
layout_height='wrap';--文本高度
Gravity='center';--对齐方式
textColor='#000000';--文本颜色

textSize='20sp';--文本大小
text="";
id="pt"
};
};
data={}
adp=ArrayAdapter(activity,android.R.layout.simple_list_item_1,data)
list.setAdapter(adp)
print"尝试爬虫中"
Http.get("https://wtznx.wodemo.net/"
,nil,nil,nil,function(code,content)
    if code==200 then
con=content:match("<li>

问题真难写 发表于 2020-6-9 21:07:58

有字数限制么?



来自解说社区客户端

问题真难写 发表于 2020-6-9 21:14:02

弄好了,至于他会加上一些意外符号,所以最好不要引用,参考一下就好了。当然如果你有耐心把那些符号删掉的话,我也没话说。



来自解说社区客户端

yph 发表于 2020-6-10 13:12:59





来自解说社区客户端

pzle 发表于 2020-6-10 20:05:29





来自解说社区客户端

开心快乐 发表于 2020-6-11 19:16:21

这是lua语言的吗?



来自解说社区客户端

问题真难写 发表于 2020-6-11 21:56:45

回复 7楼 开心快乐

是的。



来自解说社区客户端
页: [1]
查看完整版本: 最简单的wodemo爬取代码