[问题] 网页原始码抓资料问题

楼主: iostream (彻底的觉醒)   2015-05-05 21:30:28
小弟想要抓取网页某个值...
但如果从网页原始码抓会有很多相同的TAG
请问我如何抓到第N个TAG的值呢??
例如:
<td align="center" bgcolor="#FFFfff" nowrap>100</td>
<td align="center" bgcolor="#FFFfff" nowrap>200</td>
<td align="center" bgcolor="#FFFfff" nowrap>300</td>
<td align="center" bgcolor="#FFFfff" nowrap>400</td>
我用search 抓都只能抓到第一个值"100":
number = re.compile( r'nowrap>(.+)</td>.*', re.I | re.U | re.M)
content = opener.open('http://www.xxx.com.tw').read()
value = number.search( content ).groups()[ 0 ]
请问我要修改那里??或者有其他较好用的function吗??
谢谢
作者: dritchie (卍~迈斯纳效应~卍)   2015-05-05 23:44:00
re.findall
作者: phate334 (阿贤)   2015-05-06 14:26:00
可以看看beautifulsoup
作者: ug945 (ug945)   2015-05-06 14:28:00
lxml

Links booklink

Contact Us: admin [ a t ] ucptt.com