Получаю ошибку при запуске скрипта

satfan

Пользователь
Пользователь
Апр 21, 2020
98
6
8
IDLE (Python 3.10 64-bit)
Windows 10
---------------------------
Есть такой скрипт:
Python:
# coding: utf8
# == pars_playlist.py
# == select short information from Yotube playlist --
from urllib.request import urlopen
from BeautifulSoup import BeautifulSoup

print()
"pars_playlist working..."

# == get first linkof playlist ==
url = input('input link:')
url = "https://www.youtube.com/playlist?list=PLku9se_HAVOrs3p_jJzZAbV3BEODrhS3j"

fh = open('data.txt', 'w')

cur_num = 1  # index of reading page
try:
    while True:
        # -- get curent page --
        print()
        cur_num
        print()
        url
        content = urlopen(url)
        page = content.read()

        # -- cut head
        soup = BeautifulSoup(page)
        body = soup.find('body')

        # get current title
        span = body.find(id="ecw-title")
        title = span.getText()
        print()
        title

        # get list of all links
        ol = body.find(id="playlist-autoscroll-list")
        lis = ol.findAll('li')

        # soup for current page
        for idx, li in enumerate(lis):  # seek for picture
            li_title = li["data-video-title"]
            if li_title == title: break
        video_id = li["data-video-id"]

        # get picture information
        img = li.find('img')
        img_src = img['src']
        pos = img_src.find('?')
        if pos > 0: img_src = img_src[:pos]

        # get description of page
        descr = body.find(id="eow-description")
        descr_text = descr.getText()

        # save information
        fh.write(title.encode('utf8') + '\n')
        fh.write(video_id.encode('utf8') + '\n')
        fh.write(img_src.encode('utf8') + '\n')
        fh.write(descr_text.encode('utf8') + '\n')
        fh.write('\n')

        if idx >= len(lis) - 1: break

        # get next url
        idx += 1
        li = lis[idx]
        anc = li.find('a')
        href = anc['href']
        url = "https://www.youtube.com" + href

        cur_num = cur_num + 1

    # == 05 end of work ==
except:
    print()
    "exception: " + str(cur_num)
    pass
finally:
    fh.close()
    print()
    "ok"
Выдаёт ошибку:
File "E:\__Мои скрипты\1_test\parser_yotube.py", line 5, in <module>
from BeautifulSoup import BeautifulSoup
ModuleNotFoundError: No module named 'BeautifulSoup'
Process finished with exit code 1
-------------------------------------------------
Пытаюсь установить модуль, опять ошибка:
WARNING: Discarding https://files.pythonhosted.org/pack...d9f0a390a7a054bfb7b147a50b2866fb116b8909dfd37 (from https://pypi.org/simple/beautifulsoup/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement BeautifulSoup (from versions: 3.2.0, 3.2.1, 3.2.2)
ERROR: No matching distribution found for BeautifulSoup
 

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 672
478
83
pip install bs4
и в коде from bs4 import BeautifulSoup


и если в путях к скрипту есть кириллица, могут быть проблемы...
 

satfan

Пользователь
Пользователь
Апр 21, 2020
98
6
8
Спасибо regnor
Вроде кириллицы нет.
C:\Python\python.exe -m pip install BeautifulSoup
---------------------
ERROR: No matching distribution found for BeautifulSoup
Как установит конкретную версию этого модуля ?
 

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 672
478
83
Вроде кириллицы нет.
а вроде есть
Выдаёт ошибку:
File "E:\__Мои скрипты\1_test\parser_yotube.py", line 5, in <module>
from BeautifulSoup import BeautifulSoup

C:\Python\python.exe -m pip install BeautifulSoup
C:\Python\python.exe -m pip install bs4

Как установит конкретную версию этого модуля ?
что бы установить версию, например, 0.0.0, пишите так
C:\Python\python.exe -m pip install bs4==0.0.0
 

Форум IT Специалистов