Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # w2.py
- # http://arturmarques.com/edu/fp
- # https://arturmarques.com/edu/fp
- import certifi
- from urllib.request import urlopen
- from http.client import HTTPResponse
- import ssl # secure sockets layer
- ondeEstaOMeuFicheiroDeCertificados =\
- certifi.where()
- sslContext =\
- ssl.create_default_context(
- cafile=ondeEstaOMeuFicheiroDeCertificados
- )
- print(ondeEstaOMeuFicheiroDeCertificados)
- URL = "https://dn.pt/"
- resposta:HTTPResponse = urlopen(
- url = URL, #Uniform Resource Locator
- context=sslContext
- )
- resultadoEmBytesDoConsumo = resposta.read()
- resultadoEnquantoFraseUTF8 =\
- str(
- resultadoEmBytesDoConsumo,
- "UTF-8"
- )
- #print(resultadoEmBytesDoConsumo) #mostra bytes
- print (resultadoEnquantoFraseUTF8)
- """
- As hiperligações em HTML são expressas pela marca "a"
- a - anchor
- a forma geral de uma âncora
- <a href="https://dn.pt/noticia1.html" atributo2="v2">
- Hoje aconteceu o evento 1
- </a>
- """
- import bs4
- oBS4 =\
- bs4.BeautifulSoup(
- resultadoEnquantoFraseUTF8,
- "html5lib"
- )
- theAnchors = oBS4.find_all("a")
- for a in theAnchors:
- if ("href" in a.attrs.keys()):
- print(a.attrs["href"])
Advertisement
Add Comment
Please, Sign In to add comment