I wrote a code to scrape data from a website but it only executes except
part.
Actually I want to scrape application and part no. But the main problem is when I execute this program it only displays empty application and empty part no. Could you please guide me to fix this issue, thanks!
here is my code:
import requests
from bs4 import BeautifulSoup
import csv
def get_page(url):
response = requests.get(url)
if not response.ok:
print('server responded:', response.status_code)
else:
soup = BeautifulSoup(response.text, 'html.parser') # 1. html , 2. parser
return soup
def get_detail_page(soup):
try:
application = soup.find('td',class_="application",id=False).text
except:
application = 'Empty Title'
print(application)
try:
part_no = soup.find('td',class_="application",id=False)[0].text
except:
part_no = 'Empty Title'
print(part_no)
def main():
url = "https://www.automotivebulbfinder.com/philips/"
#get_page(url)
get_detail_page(get_page(url))
if __name__ == '__main__':
main()