Python Program
How can I add 3 more websites on it and print the title of eachsite?
import urllib.request
from bs4 import BeautifulSoup
def main():
url = ‘https://www.columbia.edu/’
myurl = urllib.request.urlopen(url)
soup = BeautifulSoup(myurl, ‘lxml’)
columbia = soup.find(‘h1′, class_ =’sr-only’).text
print(columbia)
main()
Answer
import urllib.request
from bs4 import BeautifulSoup
def main():
url = ‘https://www.columbia.edu/,http://www.google.com’
data = url.split(“,”)
for temp in data:
myurl = urllib.request.urlopen(temp)
soup = BeautifulSoup(myurl, ‘lxml’)
columbia = soup.find(‘h1′, class_ =’sr-only’).text
print(columbia)
main()
i could not found the site other than this which use class =sr-only but you can type by , and url in url variable as i havetype google there.
if