Как решить проблему с пустыми выходными файлами?
Подсказка: в этот вопрос необходимо включить полный код, чтобы другие могли увидеть проблему с пустыми выходными файлами и предложить способ решения проблемы.
Код:
from bs4 import BeautifulSoup
import requests
#####################################################
# Extracting the links of multiple movie transcripts
#####################################################
# How To Get The HTML
root = 'https://subslikescript.com' # this is the homepage of the website
website = f'{root}/movies' # concatenating the homepage with the movies section
result = requests.get(website)
content = result.text
soup = BeautifulSoup(content, 'lxml')
# print(soup.prettify()) # prints the HTML of the website
# Locate the box that contains a list of movies
box = soup.find('article', class_='main-article')
# Store each link in "links" list (href doesn't consider root aka "homepage", so we have to concatenate it later)
links = []
for link in box.find_all('a', href=True): # find_all returns a list
links.append(link['href'])
#################################################
# Extracting the movie transcript
#################################################
# Loop through the "links" list and sending a request to each link
for link in links:
result = requests.get(f'{root}/{link}')
content = result.text
soup = BeautifulSoup(content, 'lxml')
# Locate the box that contains title and transcript
box = soup.find('article', class_='main-article')
# Locate title and transcript
title = box.find('h1').get_text()
title = ''.join(title.split('/'))
transcript = box.find('div', class_='full-script').get_text(strip=True, separator=' ')
# Exporting data in a text file with the "title" name
with open(f'{title}.txt', 'w', encoding="utf-8") as file:
file.write(transcript)
Подробнее здесь: https://stackoverflow.com/questions/798 ... es-via-bs4
Некоторые выходные файлы пусты при очистке нескольких фильмов через bs4 [закрыто] ⇐ Python
Программы на Python
1761838948
Anonymous
Как решить проблему с пустыми выходными файлами?
Подсказка: в этот вопрос необходимо включить полный код, чтобы другие могли увидеть проблему с пустыми выходными файлами и предложить способ решения проблемы.
Код:
from bs4 import BeautifulSoup
import requests
#####################################################
# Extracting the links of multiple movie transcripts
#####################################################
# How To Get The HTML
root = 'https://subslikescript.com' # this is the homepage of the website
website = f'{root}/movies' # concatenating the homepage with the movies section
result = requests.get(website)
content = result.text
soup = BeautifulSoup(content, 'lxml')
# print(soup.prettify()) # prints the HTML of the website
# Locate the box that contains a list of movies
box = soup.find('article', class_='main-article')
# Store each link in "links" list (href doesn't consider root aka "homepage", so we have to concatenate it later)
links = []
for link in box.find_all('a', href=True): # find_all returns a list
links.append(link['href'])
#################################################
# Extracting the movie transcript
#################################################
# Loop through the "links" list and sending a request to each link
for link in links:
result = requests.get(f'{root}/{link}')
content = result.text
soup = BeautifulSoup(content, 'lxml')
# Locate the box that contains title and transcript
box = soup.find('article', class_='main-article')
# Locate title and transcript
title = box.find('h1').get_text()
title = ''.join(title.split('/'))
transcript = box.find('div', class_='full-script').get_text(strip=True, separator=' ')
# Exporting data in a text file with the "title" name
with open(f'{title}.txt', 'w', encoding="utf-8") as file:
file.write(transcript)
Подробнее здесь: [url]https://stackoverflow.com/questions/79804924/some-output-files-empty-when-scraping-multiple-movies-via-bs4[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия