【问题标题】:BeautifulSoup only returning first table rowBeautifulSoup 只返回第一行
【发布时间】:2018-10-03 04:24:45
【问题描述】:

我正在尝试从this 中抓取一张桌子 网页。

到目前为止,我可以访问该页面,使用 mechanize 单击搜索按钮,但是当我开始使用 beautifulsoup 解析 html 时遇到问题。我的代码是:

url = 'http://forestsclearance.nic.in/Wildnew_Online_Status_New.aspx'               
br = mechanize.Browser()
br.open(url)
br.select_form(name='aspnetForm')
page = br.submit(id='ctl00_ContentPlaceHolder1_Button1')
soup = BeautifulSoup(page, 'html.parser')
table = soup.findAll("table", {"id" : "ctl00_ContentPlaceHolder1_tbl"})
print table

如果您查看 HTML,我想要的表在字典中有 id,但这只会打印第一行的 html。我尝试使用 findChildren() 找到 div 标签,但它总是返回第一行。有人知道为什么会发生这种情况以及我如何抓住整张桌子吗?谢谢

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    你必须找到所有的tr标签,见下面的代码。

    url = 'http://forestsclearance.nic.in/Wildnew_Online_Status_New.aspx'               
    br = mechanize.Browser()
    br.open(url)
    br.select_form(name='aspnetForm')
    page = br.submit(id='ctl00_ContentPlaceHolder1_Button1')
    soup = BeautifulSoup(page, 'html.parser')
    table = soup.findAll('tr')
    print table
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-18
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      相关资源
      最近更新 更多