from bs4 import BeautifulSoup as Soup,Tag
import requests
url=r"https://en.wikipedia.org/wiki/Lists_of_tourist_attractions"
r = requests.get(url)
soup = Soup(r.content,"html.parser" )
for link in soup.find_all('a', href=True):
print (link['href'])
for ul in soup.findAll('div'):
print(ul.text)
for li in ul.findAll('li'):
print(li.text)
The above one is a working code. This can e used any Wikipedia pages. Issue is : I am trying to get href and title next to each other . I am not able to get this.
in the 2nd for loop its taking all the contents as div and prints in one line.
how can I print title and href adjutant to each other (li contents)
how can I print title and href adjutant to each other (li contents)
i dont understand this sentence – Nodir Rashidov