I imported BeautifulSoup, but can't make it work. Thank you for your help | Coursera Community
Coursera Header

I imported BeautifulSoup, but can't make it work. Thank you for your help

  • 18 October 2020
  • 2 replies
  • 34 views

Badge +1
import urllib.request, urllib.parse, urllib.errorfrom bs4 import BeautifulSoupimport sslctx=ssl.create_default_context()ctx.check_hostname = Falsectx.verify_mode=ssl.CERT_NONEurl= input('Enter-')html=urllib.request.urlopen(url,context=ctx).read()soup=BeautifulSoup(html,'html.parser')#retrieve all of the anchor tagstags = soup('a')for tag in tags:    print(tag.get(href,None))

Enter-wwww.dr-chuck.com/page1/htm
Traceback (most recent call last):
  File "/Users/jianpingchen/PycharmProjects/pythonProject/play.py", line 10, in <module>
    html=urllib.request.urlopen(url,context=ctx).read()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 509, in open
    req = Request(fullurl, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 328, in __init__
    self.full_url = url
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 354, in full_url
    self._parse()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 383, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'wwww.dr-chuck.com/page1/htm'

 

 


This topic has been closed for comments

2 replies

Badge +1

I edited 3 times, sorry the code automaticly

changed like this. no spaces in between 

Badge +1

solved. I made a few mistake. i copied three folders which all contain bs4. I deleted them from the folder I run the program. then redownloaded and just copied one. then it gave me anther error, which 

is easy to fix. I did put ‘ ‘ on href.