我的代码:Python:从列表解析只打印最后一项,不是全部?
from urllib2 import urlopen
from bs4 import BeautifulSoup
url = "https://realpython.com/practice/profiles.html"
html_page = urlopen(url)
html_text = html_page.read()
soup = BeautifulSoup(html_text)
links = soup.find_all('a', href = True)
files = []
base = "https://realpython.com/practice/"
def page_names():
for a in links:
files.append(base + a['href'])
page_names()
for i in files:
all_page = urlopen(i)
all_text = all_page.read()
all_soup = BeautifulSoup(all_text)
print all_soup
解析上半年收集三通,下半年应该打印出所有的HTML代码。
不幸的是,它只打印最后一个链接的HTML。
可能因为
for i in files:
all_page = urlopen(i)
它与8行代码以前的工作文件中的服务为我:目的,但我想它清理干净,并把箱子放到这两个。好吧,显然不是因为它不起作用。
虽然没有错误!