I came across this website and tried to test-run the code presented there so I could adjust it later.
Upon realising it was written in Python2, I converted it into Python 3 manually. I fixed "print" and "urlparse" statements and removed
reload(sys)
sys.setdefaultencoding("utf-8")"
(Google said it was unnecessary in Python3. Really?).
When I now run the code, I get the following output and I have no idea what to do to fix this since I am very new to Python. I looked at similar questions but the solutions there couldn't fix this code.
[*] Retrieved 89 possible stored URLs
[*] Retrieving https://web.archive.org/web/20110823161411/http://www.oct282011.com/ (1 of 89)
[*] Retrieving https://web.archive.org/web/20110830211214/http://www.oct282011.com/ (2 of 89)
[+] Adding new image: https://web.archive.org/web/20110830211214im_/http://www.oct282011.com/st.jpg
[+] Adding new image: https://web.archive.org/web/20110830211214im_/http://www.oct282011.com/itswhatyouknow_itsnotamystery_mostofyouhavefoundit.png
[+] Adding new image: https://web.archive.org/web/20110830211214im_/http://www.oct282011.com/sngl.jpg
[+] Adding new image: https://web.archive.org/web/20110830211214im_/http://www.oct282011.com/qst.png
[*] Retrieving https://web.archive.org/web/20110831172158/http://www.oct282011.com/ (3 of 89)
[+] Adding new image: https://web.archive.org/web/20110831172158im_/http://www.oct282011.com/0light.png
[+] Adding new image: https://web.archive.org/web/20110831172158im_/http://www.oct282011.com/itswhatyouknow_itsnotamystery_mostofyouhavefoundit.png
[+] Adding new image: https://web.archive.org/web/20110831172158im_/http://www.oct282011.com/sngl.jpg
[+] Adding new image: https://web.archive.org/web/20110831172158im_/http://www.oct282011.com/0.png
[*] Retrieving https://web.archive.org/web/20110903151702/http://www.oct282011.com/ (4 of 89)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-7152635ed042> in <module>
123 print("[*] Retrieved %d possible stored URLs" % len(results.assets))
124
--> 125 image_paths = get_image_paths(results)
126
127 print("[*] Retrieved %d image paths." % len(image_paths))
<ipython-input-3-7152635ed042> in get_image_paths(packed_results)
54
55 # parse out all image tags
---> 56 soup = bs4.BeautifulSoup(result)
57 image_list = soup.findAll("img")
58
~\Anaconda3\lib\site-packages\bs4\__init__.py in __init__(self, markup, features, builder, parse_only, from_encoding, exclude_encodings, **kwargs)
265 if hasattr(markup, 'read'): # It's a file-type object.
266 markup = markup.read()
--> 267 elif len(markup) <= 256 and (
268 (isinstance(markup, bytes) and not b'<' in markup)
269 or (isinstance(markup, str) and not '<' in markup)
TypeError: object of type 'NoneType' has no len()
My questions are:
- Why does Python point at three code lines (126,56,267) and why in this strange order? Are there three errors or is only the lowest-numbered line (56) of importance here?
- What is the problem and how can it be fixed? Please keep in mind I am a total beginner.
I don't know if this is important but am using Python3 in a Jupyter notebook.