반응형
● Beautiful Soup 패키지란 ?
출처 : 위키백과
#!/usr/bin/env python3
# Anchor extraction from HTML document
from bs4 import BeautifulSoup
from urllib.request import urlopen
response = urlopen('https://en.wikipedia.org/wiki/Main_Page')
soup = BeautifulSoup(response, 'html.parser')
f = open("새파일.txt", 'w')
i = 1
for anchor in soup.find_all('a'):
print(anchor.get('href', '/'))
data = str(i) + "번째 : " + anchor.get('href', '/') + "\n"
i = i + 1
f.write(data)
f.close();
실행 명령어 : python index.py
반응형