python爬蟲學習問題總結

這裏記錄一些在根據視頻/網站學習爬蟲時,遇到的一些問題。一般是由於視頻/網站時間較早,相關代碼語法網站等需要修改。這裏做一些簡單記錄,當然,可能過了半載一年,又失效了。

一、有道翻譯
解決:有道翻譯 ‘errorCode’: 50
根據有道翻譯的結果頁信息,獲取到的url爲:http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule
使用這個地址,是無法爬蟲成功的,會報錯。需要進行修改之後,纔會返回正常結果。
修改如下(去掉translate_o中的_o):

tobe_translate = input('Please input your word:')
# tobe_translate = '你好' #開發時避免每次輸入耽誤時間
data = {
    'i': tobe_translate,
    'from': 'AUTO',
    'to': 'AUTO',
    'smartresult': 'dict',
    'client': 'fanyideskweb',
    'salt': '15534990752679',
    'sign': '8068ceaab29dca41031a3695a052208a',
    'ts': '1553499075267',
    'bv': '22c4e55facde8e7a20b16e256e9fdfa1',
    'doctype': 'json',
    'version': '2.1',
    'keyfrom': 'fanyi.web',
    'action': 'FY_BY_REALTlME',
    'typoResult': 'false'}


# data轉換成request需要的數據類型
data = urllib.parse.urlencode(data).encode('utf-8')

# 發送請求
youdaofanyi = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'

整體源代碼獲取地址 https://github.com/shixin398/Python3

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章