day1 UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 2490: illegal multi...

Claire_ljy發表於2020-04-04

get方式得到網頁的資訊

  

 

#coding=utf-8
#pip install requests

#直接get到網頁的資訊
import requests
from bs4 import BeautifulSoup

response = requests.get('https://www.sogou.com/web?query=搞基建')
print(response.text)  #列印搜尋出來的全部資訊

#從 response.text  找出   <div class = 'wrwrap> </div>
soup = BeautifulSoup(response.text,'html.parser')
new_list = soup.find_all(name='div',class_='vrwrap')
print(new_list)

#可以繼續從 <div class = 'wrwrap> </div>  繼續查詢

  

 

  

 

1.錯誤程式碼

Traceback (most recent call last):
  File "D:/PycharmProjects/爬蟲/day1/s1.py", line 12, in <module>
    print(new_list)
UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 2490: illegal multibyte sequence

 

  

 

 

2.編碼格式不對

  

 

3.全部改為utf-8

   

 

4.執行成功

  

 

轉載於:https://www.cnblogs.com/venicid/p/7608181.html

相關文章