【发布时间】:2017-12-18 01:26:58
【问题描述】:
<TABLE cellSpacing=0 cellPadding=0 width=700 border=0 617px; HEIGHT: 22px 23px 536px;>
...
</TABLE>
我想像上面一样选择所有元素:标签是TABLE,并且有几个属性(cellSpacing=0,cellPadding=0,width=700,border=0)。
我尝试了以下 python 脚本:
import requests
from bs4 import BeautifulSoup
result=requests.get("http://news.scu.edu.cn/news2012/cdzx/I0201index_1.htm")
result.encoding="GBK"
soup=BeautifulSoup(result.text,"html.parser")
soup=soup.find("TABLE",attrs={"cellspacing":"0","cellpadding": "0","width":
"700","border":"0"})
print(soup)
脚本运行没有错误,但是漂亮的汤什么也没找到。这一定是错误的,如果你用Chrome打开页面(http://news.scu.edu.cn/news2012/cdzx/I0201index_1.htm),右键单击,进入inspect->Network->Doc->Response,搜索<TABLE cellSpacing=0 cellPadding=0 width=700 border=0 617px; HEIGHT: 22px 23px 536px;>,你会找到30个匹配的结果。
【问题讨论】:
标签: python python-3.x beautifulsoup html-parsing