【发布时间】:2019-10-27 18:27:51
【问题描述】:
请在此处查看我的代码: 示例网址:http://py4e-data.dr-chuck.net/comments_42.html 在以下 url 中找到的数字总和应为 (2553)。 我必须尝试使用几种技术进行总结,但使用代码顶部提供的 url 找不到正确的技术。我需要总结字符串数字。
import urllib
from urllib.request import urlopen
from bs4 import BeautifulSoup
import ssl
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# To read the file from the url
url = input('Enter - ')
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, "html.parser")
# To search for specific area of the file
tags = soup('span')
#print(tags)
sum = 0
# Filters your search further and prints the specific part as
#string
for tag in tags:
print(tag.contents[0])
#ChangeToInt = int(tag.contents[0])
#sum =+ ChangeToInt
#print(sum)
【问题讨论】:
标签: python beautifulsoup