作者iostream (彻底的觉醒)
看板Python
标题[问题] 网页原始码抓资料问题
时间Tue May 5 21:30:28 2015
小弟想要抓取网页某个值...
但如果从网页原始码抓会有很多相同的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吗??
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.195.207.241
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1430832630.A.A3F.html
1F:→ dritchie: re.findall 05/05 23:44
2F:→ phate334: 可以看看beautifulsoup 05/06 14:26
3F:→ ug945: lxml 05/06 14:28