-5

I am trying to get the 80 and 443 out of the tag

from bs4 import BeautifulSoup as bs

<ul class="ports">
<li><a href="#80">80</a>
</li>
<li><a href="#443">443</a>
</li>
</ul>
<a><div class="state">http</div><a href="http://localhost:80" target="_blank" class="link"><i class="fa fa-mail-forward">&nbsp;
</i></a>
Pierce2r
  • 15
  • 1
  • 4
  • Possible duplicate of [retrieve links from web page using python and BeautifulSoup](https://stackoverflow.com/questions/1080411/retrieve-links-from-web-page-using-python-and-beautifulsoup) – Vasilis G. May 20 '19 at 19:55

1 Answers1

0
# If Your Looking To Parse An .html File

from bs4 import BeautifulSoup
with open('test.html') as html_file:
    soup = BeautifulSoup(html_file, 'html.parser')
    ul = soup.find('ul', {'class', 'ports'})
    a = ul.findAll('a')
    Ports=[]
    for port in a:
        Ports.append(port.string)

# If Your Looking To Parse A Website

from bs4 import BeautifulSoup
import requests
session=requests.session()
endpoint = LINK
response = session.get(endpoint)
soup = BeautifulSoup(response.text, 'html.parser')
ul = soup.find('ul', {'class', 'ports'})
a = ul.findAll('a')
Ports=[]
for port in a:
    Ports.append(port.string)