#ПарсерСайтов
Код из видео:
from bs4 import BeautifulSoup
from urllib.request import urlopen
url = [
""
]
file = open('text.txt', 'a')
for x in url:
html_code = str(urlopen(x).read(), 'utf-8')
soup = BeautifulSoup(html_code, 'html.parser')
s = soup.find('title').text
file.write(s + '\n')
p = soup.find_all('p')
print(s)
for i in p:
print(i.text)
file.write(i.text + '\n')
file.write('\n\n')
file.close()
Код из видео:
from bs4 import BeautifulSoup
from urllib.request import urlopen
url = [
""
]
file = open('text.txt', 'a')
for x in url:
html_code = str(urlopen(x).read(), 'utf-8')
soup = BeautifulSoup(html_code, 'html.parser')
s = soup.find('title').text
file.write(s + '\n')
p = soup.find_all('p')
print(s)
for i in p:
print(i.text)
file.write(i.text + '\n')
file.write('\n\n')
file.close()