Python Program Add 3 Websites Print Title Site Import Urllibrequest Bs4 Import Beautifulso Q37301060

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.

test.py-CA File Edit Format Run Options Window Help 111b.request mport Beautitulsoup -ロ× 13 python pitest.py (B.7.0) 3.7.0 Sh-XPython 3.7.0 Shell test.py-C:/Users/Administrator/Desktop test.py B.7.0 File Edit Format Run Options Window Help import url

if

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.