html decode

error:

 /usr/bin/python3 /home/cor/webscrappython/Web_Scraping_with_Python/chapter01/link_crawler2.py
Downloading:http://example.webscraping.com
Downloading --- 5
Traceback (most recent call last):
  File "/home/cor/webscrappython/Web_Scraping_with_Python/chapter01/link_crawler2.py", line 38, in <module>
    link_crawler('http://example.webscraping.com', '/(index|view)')
  File "/home/cor/webscrappython/Web_Scraping_with_Python/chapter01/link_crawler2.py", line 16, in link_crawler
    for link in get_links(html):
  File "/home/cor/webscrappython/Web_Scraping_with_Python/chapter01/link_crawler2.py", line 34, in get_links
    return webpage_regex.findall(html)
TypeError: cannot use a string pattern on a bytes-like object

  solution:

 

you want to convert html (a byte-like object) into a string using .decode,
e.g. html = response.read().decode('utf-8')

  

 

posted @ 2020-03-25 17:14  碧水东流至此回  阅读(145)  评论(0编辑  收藏  举报