Skip to content Skip to sidebar Skip to footer

How Web Scrape Data From This Line .. There Is No Div And No Class Element I Can't Find.i Want To Extract Data From That Line??how

==$0 '1.'the purpose of our lives is to be happy.' - ' Dalai Lama

there is many quotes like above form tags and I can't

Solution 1:

import requests
from bs4 import BeautifulSoup
from pprint import pp


defmain(url):
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'lxml')
    x = [x.get_text(strip=True, separator=" ") for x in soup.select(
        'span[data-parade-type="promoarea"] .figure_block ~ p')]

    goal = [i for i in x if i[0].isdigit()]
    pp(goal)


main('https://parade.com/937586/parade/life-quotes/')

Note, If you are using Windows machine, DO NOT forget to include from_encoding= equal to the encoding used by your sys.

Ref: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#encodings

Otherwise:

print("\n".join(goal))

Post a Comment for "How Web Scrape Data From This Line .. There Is No Div And No Class Element I Can't Find.i Want To Extract Data From That Line??how"