python beautifulsoup 给出 table 的特定部分

python beautifulsoup giving specific part of table

page = requests.get("http://www.freejobalert.com/upsc-recruitment/16960/#Engg-Services2019")
c = page.content
soup=BeautifulSoup(c,"html.parser")
tables=soup.find_all("table",{"style":"width: 500px;"})
print(tables)

本页有 10 个 table。但它只给出 table 的特定部分而不是完整的 table。 它没有完全给出所有 table。 我期待第二个 table 。但就像第一张截图一样

此代码给出了 14 个条目,不应考虑其中的第一个和最后一个。最后一个是 javascript 代码。

您只需要将解析器更改为更宽松的解析器,更多内容可在此处找到 https://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser

page = requests.get("http://www.freejobalert.com/upsc-recruitment/16960/#Engg-Services2019")
c = page.content
soup=BeautifulSoup(c,"html5lib")
tables=soup.find_all("table")

for table in tables[1:-1]:
      print (table.text)

如果更改解析器显示错误,请在您的环境中安装 html5lib,如下所示 pip3 安装 html5lib