国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

[Python3]爬蟲HTTP Error 500錯誤,報錯信息:urllib.error.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR

這篇具有很好參考價值的文章主要介紹了[Python3]爬蟲HTTP Error 500錯誤,報錯信息:urllib.error.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

報錯代碼

# @author tianyi
# {Time}-2022-09-11 08:40


import urllib.parse
import urllib.request

def create_request(page):

    base_url = 'https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=0&limit=20'

    data = {
        'start' :(page-1)*20,
        'limit' :20
    }
    print(data)
    print('---------------------------------------------')
    data = urllib.parse.urlencode(data)
    url = base_url +data
    print(url)

    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'
    }
    request = urllib.request.Request(url=url, headers=header)

    return request

def get_connect(request):
    response = urllib.request.urlopen(request)
    connect = response.read().decode('utf-8')
    return connect


def down_load(page,connect):
    with open('douban_'+str(page)+'.json','w',encoding='utf-8') as fp:
        fp.write(connect)


if __name__ == '__main__':
    start_page = int(input('請輸入開始的頁數(shù):'))
    end_page = int(input('請輸入結束的頁數(shù):'))

    for page in range(start_page, end_page+1):
        request = create_request(page)
        print(request)
        connect = get_connect(request)

        down_load(page, connect)

之后報下面的錯誤:

C:\Users\27964\AppData\Local\Microsoft\WindowsApps\python3.10.exe H:/pythonProject/pythonProject2/練習3/ajax_get.py
請輸入開始的頁數(shù):1
請輸入結束的頁數(shù):1
{'start': 0, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=0&limit=20start=0&limit=20
<urllib.request.Request object at 0x000001F566883FD0>
Traceback (most recent call last):
  File "H:\pythonProject\pythonProject2\練習3\ajax_get.py", line 47, in <module>
    connect = get_connect(request)
  File "H:\pythonProject\pythonProject2\練習3\ajax_get.py", line 30, in get_connect
    response = urllib.request.urlopen(request)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 525, in open
    response = meth(req, response)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 563, in error
    return self._call_chain(*args)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR

問題解決:

發(fā)現(xiàn)報錯代碼:urllib.error.httperror: http error 500: internal server error,python,爬蟲,http,python

修改代碼:

# @author tianyi
# {Time}-2022-09-11 08:40


import urllib.parse
import urllib.request

def create_request(page):

    base_url = 'https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&'

    data = {
        'start' :(page-1)*20,
        'limit' :20
    }
    print(data)
    print('---------------------------------------------')
    data = urllib.parse.urlencode(data)
    url = base_url +data
    print(url)

    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'
    }
    request = urllib.request.Request(url=url, headers=header)

    return request

def get_connect(request):
    response = urllib.request.urlopen(request)
    connect = response.read().decode('utf-8')
    return connect


def down_load(page,connect):
    with open('douban_'+str(page)+'.json','w',encoding='utf-8') as fp:
        fp.write(connect)


if __name__ == '__main__':
    start_page = int(input('請輸入開始的頁數(shù):'))
    end_page = int(input('請輸入結束的頁數(shù):'))

    for page in range(start_page, end_page+1):
        request = create_request(page)
        print(request)
        connect = get_connect(request)

        down_load(page, connect)

urllib.error.httperror: http error 500: internal server error,python,爬蟲,http,python
運行成功:

C:\Users\27964\AppData\Local\Microsoft\WindowsApps\python3.10.exe H:/pythonProject/pythonProject2/練習3/ajax_get.py
請輸入開始的頁數(shù):1
請輸入結束的頁數(shù):10
{'start': 0, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=0&limit=20
<urllib.request.Request object at 0x000001D9044B3FD0>
{'start': 20, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=20&limit=20
<urllib.request.Request object at 0x000001D904867220>
{'start': 40, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=40&limit=20
<urllib.request.Request object at 0x000001D9044B3FD0>
{'start': 60, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=60&limit=20
<urllib.request.Request object at 0x000001D904866A10>
{'start': 80, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=80&limit=20
<urllib.request.Request object at 0x000001D9044B3FD0>
{'start': 100, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=100&limit=20
<urllib.request.Request object at 0x000001D904866A40>
{'start': 120, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=120&limit=20
<urllib.request.Request object at 0x000001D9044B3FD0>
{'start': 140, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=140&limit=20
<urllib.request.Request object at 0x000001D904864B20>
{'start': 160, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=160&limit=20
<urllib.request.Request object at 0x000001D9044B3FD0>
{'start': 180, 'limit': 20}
---------------------------------------------
https://movie.douban.com/j/chart/top_list?type=7&interval_id=100%3A90&action=&start=180&limit=20
<urllib.request.Request object at 0x000001D904867220>

urllib.error.httperror: http error 500: internal server error,python,爬蟲,http,python
爬到的數(shù)據(jù):
urllib.error.httperror: http error 500: internal server error,python,爬蟲,http,python文章來源地址http://www.zghlxwxcb.cn/news/detail-593027.html

到了這里,關于[Python3]爬蟲HTTP Error 500錯誤,報錯信息:urllib.error.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包