Why does the source code of this web page crawl down with Python and then parse with BeautifulSoup to lose character?

Source: Internet
Author: User

Reply content:

You're the only one to thank the bad guys ...
Why do you have to be so impatient to learn, the foundation is not solid ah, too aggressive, it is clear that there is no clear idea ...

The first programming to have the default encoding, that is, at the beginning of the file plus
 # -*- coding: utf-8 -*-
You are Python2 code before add # Coding:utf-8

See three articles from Python training Huanggo
Python Development crawler Chinese character coding is no longer a problem:
will be python2 Chinese characters will appear garbled things once said clearly
Article/python_bianma.md at Master Pythonpeixun/article GitHub
Python crawler access to multiple websites, Chinese encoding processing.
Python crawler access to multiple websites, Chinese encoding processing.
Python3 access to Sina home Chinese processing
Python3 access to Sina home Chinese processing


It may be lost in the place where you turn around.
ur = list (ur)
ur = ur[:-1]
****************
 ur = res.contents[0]    ur = list(ur)    ur = ur[:-1]    temp = unicode(ur[0])    for index in range(0, len(ur), 4):        temp = unicode(ur[index])        print temp.strip()        print ur[index+1].string        print ur[index+1]['href']        print '\n'
It seems response back with two decode behind a change encode should be good ...

Decode is to turn the parentheses into Unicode.

Encode is Unicode turned into parentheses, that is UTF-8

Unicode is a transit point.


No more, the same building ignore ... Or use the Requests library to handle HTTP requests.
  • Related Article

    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.