Python Forum
Wrong output in python3 via terminal on mac
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wrong output in python3 via terminal on mac
#3
(Jun-24-2018, 11:02 PM)obligato Wrote: However, each time I run the code it keeps asking me to enter file name while there is no input line in my file.
It should not do that,try running from Terminal command line if you run from a IDE/editor.
Even if fix import the code will never work because tags = soup('a'),there are no links(which a search for) on that page.
To show a example that work.
import urllib.request
from bs4 import BeautifulSoup

url = 'http://py4e-data.dr-chuck.net/comments_42.html'
html = urllib.request.urlopen(url)
soup = BeautifulSoup(html, "html.parser")

td_tag = soup.find_all('span', class_="comments")
total = sum(int(td.text) for td in td_tag)
print('total is {}'.format(total))
Output:
total is 2553
Should also drop urllib and use Requests.
Reply


Messages In This Thread
RE: Wrong output in python3 via terminal on mac - by snippsat - Jun-25-2018, 12:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Django serving wrong template at the wrong address with malformed urls.py (redactor a Drone4four 2 2,675 Aug-17-2020, 01:09 PM
Last Post: Drone4four

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020