We have an internal web page with lists of IP addresses. The IP addresses are enclosed as list items. I am still somewhat new to Python and was hoping for a bit of direction. I would like to end up with a text file that comma separates these IPs.
<li>192.168.1.1</li>
I am using a publicly available website for my question, but the HTML source is similar.
import requests
from bs4 import BeautifulSoup
URL = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_lists_intro'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
list_items = soup.find_all('li')
print(list_items)
[<li>Coffee</li>, <li>Tea</li>, <li>Milk</li>, <li>Coffee</li>, <li>Tea</li>, <li>Milk</li>]
How can I further parse the output from list_items into a list/text file such as the following:
Coffee, Tea, Milk, Coffee, Tea, Milk
Thank You!
print([e.text for e in list_items])print(", ".join([e.text for e in list_items]))