我想知道为什么这是正确的:
for heading in soup.find_all("td", class_="paraheading"):
key = " ".join(heading.text.split()).rstrip(":")
if key in columns:
print key
next_td = heading.find_next_sibling("td", class_="bodytext")
value = " ".join(next_td.text.split())
print value
if key == "Industry Categories":
print key
ic_next_td = heading.find_next_sibling("td", class_="bodytext")
for value in ic_next_td.strings:
print value
这不是:
for heading in soup.find_all("td", class_="paraheading"):
key = " ".join(heading.text.split()).rstrip(":")
if key in columns:
print key
next_td = heading.find_next_sibling("td", class_="bodytext")
value = " ".join(next_td.text.split())
print value
if key == "Industry Categories":
print key
ic_next_td = heading.find_next_sibling("td", class_="bodytext")
for value in ic_next_td.strings:
print value
print value
注意在第一个代码块中看似双缩进。
下for value in ic_next_td.strings:
一个缩进级别不会是该行的一个额外缩进级别吗?
谢谢