作者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://www.ptt.cc/bbs/Python/M.1430832630.A.A3F.html
→ dritchie: re.findall 05/05 23:44
→ phate334: 可以看看beautifulsoup 05/06 14:26
→ ug945: lxml 05/06 14:28