Python appears can ' t use a string pattern on a Bytes-like object

Source: Internet
Author: User

    1. # Coding=utf-8
    2. Import Urllib.request
    3. Import re
    4. url = ' http://www.163.com '
    5. File = ' d:/test.html '
    6. data = Urllib.request.urlopen (URL). Read ()
    7. R1 = re.compile (' <.*?> ')
    8. c_t = R1.findall (data)
    9. Print (c_t)

After the discovery reads down, runs to line 9th, which appears:

Can ' t use a string pattern on a Bytes-like object

Looked up, is said 3.0 now the parameter changes, now read is bytes-like, but the parameter requirements are chart-like, look for a bit, add a code:

data = Data.decode (' Utf-8 ')

It can be used normally before it is used in regular use.

Python appears can ' t use a string pattern on a Bytes-like object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.