无法在类似字节的对象(Python)上使用字符串模式

无法在类似字节的对象(Python)上使用字符串模式,python,python-3.x,web-crawler,re,Python,Python 3.x,Web Crawler,Re,我正在用python创建一个爬虫来列出网站中的所有链接,但我遇到了一个错误,我看不出是什么原因导致了它 错误是: Traceback (most recent call last): File "vul_scanner.py", line 8, in <module> vuln_scanner.crawl(target_url) File "C:\Users\Lenovo x240\Documents\website\website\sp

我正在用python创建一个爬虫来列出网站中的所有链接,但我遇到了一个错误,我看不出是什么原因导致了它 错误是:

Traceback (most recent call last):
  File "vul_scanner.py", line 8, in <module>
    vuln_scanner.crawl(target_url)
  File "C:\Users\Lenovo x240\Documents\website\website\spiders\scanner.py", line 18, in crawl
    href_links= self.extract_links_from(url)
  File "C:\Users\Lenovo x240\Documents\website\website\spiders\scanner.py", line 15, in extract_links_from
    return re.findall('(?:href=")(.*?)"', response.content)
  File "C:\Users\Lenovo x240\AppData\Local\Programs\Python\Python38\lib\re.py", line 241, in findall
    return _compile(pattern, flags).findall(string)
TypeError: cannot use a string pattern on a bytes-like object
在vul_scanner.py文件中:

import scanner
# To ignore numpy errors:
#     pylint: disable=E1101


target_url = "https://www.amazon.com"
vuln_scanner = scanner.Scanner(target_url)
vuln_scanner.crawl(target_url)
我运行的命令是:python vul_scanner.py

return re.findall('(?:href=")(.*?)"', response.content)
response.content在本例中为二进制类型。因此,您可以使用
response.text
,这样您就可以得到纯文本,并可以按照您现在的计划进行处理,或者您可以查看以下内容:

如果你想继续沿着二元路走下去


干杯

分享完整的错误信息可能有助于人们回答您的问题
return re.findall('(?:href=")(.*?)"', response.content)