我按照一门课程学习Python,我尝试做一些拼抢,但是我的程序有些困难(我使用PyCharm):
import urllib2
from BeautifulSoup import BeautifulSoup
url = urllib2.urlopen(raw_input("Enter - "))
soup = BeautifulSoup(url, "html.parser")
tags = soup("span")
total = []
for tag in tags:
total.append(int(tag))
print sum(total)
print len(total)
问题是当我运行代码时,我要废弃的页面打开但代码没有运行,即我没有总和和列表的长度
答案 0 :(得分:0)
你是什么意思"数字"数字?看看,如果这是你的意思:
import requests
from lxml import html
response = requests.get("http://py4e-data.dr-chuck.net/comments_35201.html").text
tree = html.fromstring(response)
title = [item.text for item in tree.cssselect(".comments")]
for x in range(len(title)):
print("{} {}".format(x+1,title[x]))
部分结果:
1 97
2 91
3 88
4 87
5 87
6 86