TypeError: Type str doesn't support the buffer API # find method?

前端 未结 2 1669
误落风尘
误落风尘 2021-01-12 02:36

Here is my input:


..........

      
      
2条回答
  • 2021-01-12 03:02

    You can also make the data coming from your input a str object, like this:

    url = "http://www.google.com"
    req = request.Request(url)
    response = request.urlopen(req)
    page = str(response.read()) # make it a str object
    print(page[page.find('id='):]) # now you don't need a b in front of your string
    
    0 讨论(0)
  • 2021-01-12 03:03

    You can't use bytes.find() to find a str object inside a bytes object(since they're different types, a str can't be inside bytes).
    You can, however, look for a bytes object inside it. This should work:

    start_link = input.find(b' <p class="js-tweet-text tweet-text" ')
    

    Btw, you should be using an html parser if you're parsing html.

    0 讨论(0)
提交回复
热议问题