这行得通...
print soup.findAll('td',{ "class" : "green center" })
但我只需要文字,这不起作用......
print soup.findAll('td',{ "class" : "green center" }).text
这是我如何使用它。
#!python27
import fileinput
import sys
import BeautifulSoup
from BeautifulSoup import BeautifulSoup
import re, urllib
filename = "url.txt"
LineNumber=0
f=open(filename)
lines=f.readlines()
f.close()
for line in lines:
filehandle = urllib.urlopen("http://kat.ph/usearch/"+lines[LineNumber]+"/")
line = filehandle.read()
soup = BeautifulSoup(line)
print soup.findAll('td',{ "class" : "green center" }).text
print soup.findAll('td',{ "class" : "red lasttd center" }).text
print LineNumber
LineNumber=LineNumber+1
filehandle.close()
Post script url.txt 只是要运行的搜索列表。