我正在爬取一个页面,在该页面的表格中,我要获取所有的<tr>
元素,代码如下:
r = requests.get("http://lol.esportswikis.com/wiki/G2_Esports/Match_History")
s = BeautifulSoup(r.content, "lxml")
tr = s.find_all("table", class_="wikitable sortable")[0].find_all("tr")[3:]
print tr[0]
其输出结果为:
<tr style="background-color:#C6EFCE"><td>...</td> ... <td>...</td></tr>
现在我想获取<tr>
标签的样式,但是我不知道如何做。例如,如果我这样做:
for item in tr[0]:
print item
显然,它只是打印<td> ... </td>
的内容。我想我可能可以做类似于print tr[0].something
的事情,比如tr[0].tag
,但到目前为止,我尝试过的所有方法都没有得到我想要的结果。