This program to extract the text from an HTML address tag using Python.
CODE:
import requests from bs4 import BeautifulSoup url = 'https://www.justdial.com/Pune/Amrit-Guest-House-Behind-Hoshtel99-Koregaon-Park/020PXX20-XX20-240110203615-G5H8_BZDET?ncatid=10255012&area=&search=Top%20Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park%20in%20Pune&mncatname=Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park&search_id=a0b376a253daae9a9afb91e2da4229f66d238683c1e07ff9daf9f023b4fef7e8&abd_btn=&abd_heading=&isFreetxt=1&bd=2' # Replace with the actual URL response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser') address_tag = soup.find('address') address_text = address_tag.get_text(strip=True) print("Text from <address> tag:")print(address_text)
I got this following error while running the above code.
Solution:
import requests from bs4 import BeautifulSoup url = 'https://www.justdial.com/Pune/Amrit-Guest-House-Behind-Hoshtel99-Koregaon-Park/020PXX20-XX20-240110203615-G5H8_BZDET?ncatid=10255012&area=&search=Top%20Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park%20in%20Pune&mncatname=Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park&search_id=a0b376a253daae9a9afb91e2da4229f66d238683c1e07ff9daf9f023b4fef7e8&abd_btn=&abd_heading=&isFreetxt=1&bd=2' # Replace with the actual URL headers = { "User-Agent" : "My Agent" } response = requests.get(url, headers= headers) soup = BeautifulSoup(response.content, 'html.parser') address_tag = soup.find('address') address_text = address_tag.get_text(strip=True) print("Text from <address> tag:") print(address_text)
VIDEO GUIDE:
Post your comments / questions
Recent Article
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
Related Article