有人可以幫我解析一下嗎?我有很大的麻煩。我正在解析這個site的信息。Python解析幫助
下面是幾行代碼從表中提取數據與2個冠軍和4個值:
for x in soup.findAll(attrs={'valign':'top'}):
print(x.contents)
make_list = x.contents
print(make_list[1]) #trying to select one of the values on the list.
當我嘗試與make_list[1]
行打印出來,它會得到一個錯誤。但是,如果我拔出最後2行,我會以列表格式獲得我想要的html,但我似乎無法分開單個或篩選它們(取出html標記)。任何人都可以幫忙嗎?
這裏是一個輸出示例,我想在這裏具體說明。我不知道正確的正則表達式:
['\n', <td align="left">Western Mutual/Residence <a href="http://interactive.web.insurance.ca.gov/companyprofile/companyprofile?event=companyProfile&doFunction=getCompanyProfile&eid=3303"><small>(Info)</small></a></td>, '\n', <td align="left"><div align="right"> 355</div></td>, '\n', <td align="left"><div align="right">250</div></td>, '\n', <td align="left"> </td>, '\n', <td align="left">Western Mutual/Residence <a href="http://interactive.web.insurance.ca.gov/companyprofile/companyprofile?event=companyProfile&doFunction=getCompanyProfile&eid=3303"><small>(Info)</small></a></td>, '\n', <td align="left"><div align="right"> 320</div></td>, '\n', <td align="left"><div align="right">500</div></td>, '\n']
什麼是預期輸出 – The6thSense
「它得到一個錯誤」。什麼是錯誤? – Kevin
@Kevin IndexError:列表索引超出範圍 –