Python 与BeautifulSoup的奇怪行为

Python 与BeautifulSoup的奇怪行为,python,beautifulsoup,Python,Beautifulsoup,我使用以下代码查找源代码中与以下网页对应的所有行span=“7” http://www.sebi.gov.in/sebiweb/investment/FIILatestSE.jsp?period=month 令人惊讶的是,尽管有42个rowspan=“7”,但find_all结果并没有显示所有这些,而只显示了其中的22个。为什么? 这是我的代码: from bs4 import BeautifulSoup import csv import time import mechanize impo

我使用以下代码查找源代码中与以下网页对应的所有行span=“7”

http://www.sebi.gov.in/sebiweb/investment/FIILatestSE.jsp?period=month
令人惊讶的是,尽管有42个rowspan=“7”,但find_all结果并没有显示所有这些,而只显示了其中的22个。为什么?

这是我的代码:

from bs4 import BeautifulSoup
import csv
import time
import mechanize
import cookielib

# Browser
br = mechanize.Browser()

# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# Want debugging messages?
#br.set_debug_http(True)
#br.set_debug_redirects(True)
#br.set_debug_responses(True)

br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
print "Obtaining FII data from SEBI..."
r = br.open('http://www.sebi.gov.in/sebiweb/investment/FIILatestSE.jsp?period=month')
data = r.read()
messages=[]
messages.append("FII data obtained from SEBI")
soup=BeautifulSoup(data)
list=soup.find_all(rowspan="7")

我通过添加xml参数解决了这个问题

soup = BeautifulSoup(data, 'xml')

为了澄清,请确保已安装lxml。如果安装了任何其他解析器,它将覆盖lxml,并且解析可能不是预期的

我运行了youre code并打印了len(列表),它打印了
42
,这完全取决于。即使是不同版本的lxml也可以为您提供不同的HTML解析结果,但如果您确实安装了lxml,它将是默认的解析器。@ChristianCareaga,它仍然为我提供了22