我正在用pythonforandroid(sl4a)编写一个android应用程序,我想让它搜索一个笑话网站并提取一个笑话。那就告诉我那个笑话好让我清醒过来。到目前为止,它将原始的html源文件保存到一个列表中,但是我需要它来创建一个新的列表,方法是在html标记之间保存数据,然后将这些数据读给我。我无法使用解析器。代码如下:
import android
droid = android.Android()
import urllib
current = 0
newlist = []
sock = urllib.urlopen("http://m.funtweets.com/random")
htmlSource = sock.read()
sock.close()
rawhtml = []
rawhtml.append (htmlSource)
while current < len(rawhtml):
while current != "<div class=":
if [current] == "</b></a>":
newlist.append (current)
current += 1
print newlist
方法如下: [代码] 进口re 导入urllib2
[/代码]
在android中使用这个LIB来解析HTML
http://jsoup.org/
它的范围和开发人员广泛接受的LIB它也可以用于python:)相关问题 更多 >
编程相关推荐