Why are the characters lost after the source code of this webpage is crawled in python and parsed using beautifulsoup?

Source: Internet
Author: User
Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Reply content: Thank you again for not praising the bad guys ......
Why are you so eager to learn this? the foundation is not solid, so it is too aggressive. obviously there is no clear idea...

First, the default encoding is required for programming, that is, to add

 # -*- coding: utf-8 -*-
Add # coding: UTF-8 before python2 code.

Read three articles on python training for brother Huang
Chinese character encoding for python development crawlers is no longer a problem:
Clear the Chinese characters in python2 with garbled characters at one time
Article/python_bianma.md at master · pythonpeixun/article · GitHub
Python crawlers access multiple websites and process Chinese code.
Python crawlers access multiple websites and process Chinese code.
How does python3 access the sina homepage in Chinese?
How does python3 access the sina homepage in Chinese?


It may be lost in your transfer.
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 that response is followed by two decodes and it should be nice to change the encode...

Decode converts the brackets to Unicode.

Encode is Unicode into brackets, is the UTF-8

Unicode is a transfer station


No, the same building ignore... Use the Requests library to process http Requests.

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.