国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

網頁爬蟲 - 關于python3.x 編寫爬蟲異常問題請各位大神幫忙!

瀏覽:98日期:2022-09-01 09:42:58

問題描述

這段代碼一直出現異常,但只要把導入的庫稍加更改在python2.x中運行是沒有問題的,請問大神問題出在哪?出現的異常也總變,小弟初學爬蟲,請賜教!

import urllib.errorimport urllib.requestimport urllib.parseurl = ’http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=https://www.baidu.com/link HTTP/1.1’data = {}data[’type’]= ’AUTO’data[’i’] = ’I am fine !’data[’doctype’] = ’json’data[’xmlVersion’] = ’1.8’data[’keyfrom’] = ’fanyi.web’data[’ue’] = ’UTF-8’data[’action’] = ’FY_BY_CLICKBUTTON’data[’typoResult’] = ’true’head = {}head[’User-Agent’]= ’Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0’ try: data = urllib.parse.urlencode(data).encode(’utf-8’) req = urllib.request.Request(url,data,head) response = urllib.request.urlopen(req) html = response.read().decode(’utf-8’) print(html)except urllib.error.HTTPError as e: print (’Error code : ’,e.code)except urllib.error.URLError as e: print (’The reason: ’,e.reason)

昨天是這樣的:網頁爬蟲 - 關于python3.x 編寫爬蟲異常問題請各位大神幫忙!

今天運行就這樣了:網頁爬蟲 - 關于python3.x 編寫爬蟲異常問題請各位大神幫忙!

問題解答

回答1:

刪掉url后面 HTTP/1.1,url后面加它干嘛。。

網頁爬蟲 - 關于python3.x 編寫爬蟲異常問題請各位大神幫忙!

回答2:

Python3不用解碼和編碼啦,還有些模塊的用法不一樣了,自己看一下Python3的文檔吧

回答3:

網頁爬蟲 - 關于python3.x 編寫爬蟲異常問題請各位大神幫忙!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 盘山县| 曲沃县| 孙吴县| 策勒县| 阿勒泰市| 金昌市| 平泉县| 淮阳县| 霍邱县| 洪湖市| 仁化县| 通化市| 柞水县| 绥阳县| 潞城市| 静安区| 务川| 阳城县| 尼玛县| 遂宁市| 武穴市| 邢台市| 青河县| 阜城县| 额尔古纳市| 石泉县| 河北省| 高尔夫| 紫金县| 新晃| 枝江市| 大新县| 喜德县| 乌审旗| 栖霞市| 通山县| 奉节县| 巴青县| 汕头市| 苗栗市| 增城市|