1
웹 크롤러를 만들고 pycharm에서 프로그램을 실행하여 URL의 앵커 태그를 검색하려고합니다. 그러나 내가 얻은 결과는 입력 한 바로 그 URL과 같습니다. . 코드는 다음과 같습니다 : 여기에서 주목해야 할파이썬에서 웹 크롤러를 만들 때 앵커 태그 가져 오기
import urllib.request,urllib.parse,urllib.error
from bs4 import BeautifulSoup
import ssl
ctx=ssl.create_default_context()
ctx.check_hostname=False
ctx.verify_mode=ssl.CERT_NONE
url=input("https://en.wikipedia.org/wiki/Apple_Inc.")
html=urllib.request.urlopen(url, context=ctx).read()
soup=BeautifulSoup(html, 'html.parser')
tags=soup("a")
for tag in tags:
print(tag.get("href",None))
한 가지 URLLIB 라이브러리 만 urllib.error 사용 명령문으로 보여주는 두 urllib.request 및 urllib.parse 어느 내가 할 수 없기 때문에 사용하지 않는 문을 보여주는된다는 것이다 이유를 이해하십시오.
이 프로그램의 출력은 https://en.wikipedia.org/wiki/Apple_Inc입니다.
저는 python 3.5.1 및 pycharm 커뮤니티 에디션을 사용하고 있습니다.