Beautiful Soup UserWarning: не был явно указан парсер - PullRequest
0 голосов
/ 18 февраля 2019

Я хочу извлечь только текст из исходного кода (html-коды, которые являются div id "col-green").Когда я хочу извлечь только текст в исходном коде, появляется предупреждение.

from bs4 import BeautifulSoup
import requests
page_link = 'http://drneclayazicioglu.meb.k12.tr/'
page_response = requests.get(page_link, timeout=5)
page_content = BeautifulSoup(page_response.content, "html.parser")
source_code=(page_content.findAll('div',attrs={"id":"col-green"}))
soup = BeautifulSoup(source_code)   #error line here...

Ошибка в том, что:

Warning (from warnings module):
  File "C:/Users/Emre/Desktop/python.py", line 7
    soup = BeautifulSoup(source_code)
UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 7 of the file C:/Users/Emre/Desktop/python.py. To get rid of this warning, pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor.

Ответы [ 2 ]

0 голосов
/ 19 февраля 2019

Вам не нужно использовать снова BeautifulSoup.Ваш source_code возвращает bs4.element.ResultSet, и вы можете получить текст следующим образом:

for a in source_code:
    print a.text

ВЫХОД:

Duyurular
Ocak 2019 GELİR LİSTEMİZ 11.02.2019 00:18GİDER LİSTEMİZ OCAK AYI11.02.2019 
00:11Yönetici Görevlendirme Yönetmeliğinde Değişiklik10.02.2019 23:512018-2019 
ÖGRETIM YILI  ÖĞRETMENLER KURULU TOPLANTISI YAPILDI05.02.2019 18:49BİN DÖRT YÜZ 
ÖĞRENCİ 5 YETİME KARDEŞ OLDU!!!06.01.2019 11:18 
Devamı...
0 голосов
/ 18 февраля 2019
from bs4 import BeautifulSoup
import requests
page_link = 'http://drneclayazicioglu.meb.k12.tr/'
page_content= BeautifulSoup(requests.get(page_link).text, "html.parser")
source_code=(page_content.findAll('div',attrs={"id":"col-green"}))
soup = BeautifulSoup(source_code)

Я надеюсь, что это работает!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...