Roy Roy - 4 months ago 91
Python Question

Python-Web Scraping. How to get the elements that are highlighted are bold alone?

I am beginner in Web scraping with python. I am trying to web scrape using python - beautiful soup and selenium. My objective is to get the highlighted elements [ In this case , it's the 1200 Sqft and event alone]. This is my HTML Code,

<section class='space-section'>
<table class='space-features'>
<i class='icon-measuringtape'></i>
<p class='space-feature-name'>1,200 sqft</p>
<td class='disabled'>
<i class='icon-store'></i>
<p class='space-feature-name'>Retail</p>
<td class='disabled'>
<i class='icon-restaurant'></i>
<p class='space-feature-name'>Bar &amp; Restaurant</p>
<td class=''>
<i class='icon-event'></i>
<p class='space-feature-name'>Event</p>
<td class='disabled'>
<i class='icon-share'></i>
<p class='space-feature-name'>Shop Share</p>
<td class='disabled'>
<i class='icon-star'></i>
<p class='space-feature-name'>Unique</p>

and the URL of my Website is this -

I want my output print statement to be something like this, SQFT - 1200 sqft , Retail - No, Bar and Restaurant - No, Event - Yes, Shop share - No, Unique - No. Can you tell me a solution for this?


try this code:

from selenium import webdriver
from bs4 import BeautifulSoup

driver = webdriver.Chrome()
url= ""

content = driver.page_source.encode('utf-8').strip()
soup = BeautifulSoup(content,"html.parser")
options=[y.text for y in feature]
options1=[y.text.strip() for y in disabled]

for x in options:
    if 'sqft' in x:
        print "SQFT - ",x
    elif x in options1:
            print x , " - No"
        print x , " - Yes"

This will print:

SQFT -  1,200 sqft
Retail  - No
Bar & Restaurant  - No
Event  - Yes
Shop Share  - No
Unique  - No

Hope this is what you want