此代码不打印公司名单作为reqiured。 它没有达到第一个标签内 如果我在第一个标签内写入“print'文字'”,它不会打印它。 BeautifulSoup正在为不同的网站编写不同的代码。 任何建议为什么它不起作用?标签里面的beautifulsoup无法正常工作
from bs4 import BeautifulSoup
import urllib
request = urllib.urlopen('http://www.stockmarketsreview.com/companies_sp500/')
html = request.read()
request.close()
soup = BeautifulSoup(html)
for tags in soup.find_all('div', {'class':'mainContent'}):
for row in tags.find_all('tr'):
for column in row.find_all('td'):
print column.text
此代码对我的作品.. – Totem
也许检查您的缩进实际代码。当你运行这个时,你会得到什么? – Totem
你是否在使用'lxml'作为解析器?某些版本的lxml与某些版本的基础libxml在解析某些HTML时遇到了麻烦。 –