Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

beautifulsoup - How to scrape the Event details using python

I am trying to scrape the complete date details as: SATURDAY, JANUARY 30, 2021 AT 8:30 PM UTC+05:30 – 12:30 AM UTC+05:30

Code tag:

<div class="j83agx80 cbu4d94t obtkqiv7 sv5sfqaa">
    <div class="bi6gxh9e aov4n071">
        <h2 class="gmql0nx0 l94mrbxd p1ri9a11 lzcic4wl d2edcug0 hpfvmrgz" dir="auto">
            <span class="d2edcug0 hpfvmrgz qv66sw1b c1et5uql rrkovp55 a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v hnhda86s jdix4yx3 hzawbc8m" dir="auto">
                ::before
                "SATURDAY, JANUARY 30, 2021 AT 8:30 PM UTC+05:30 – 12:30 AM UTC+05:30"
                ::after
            </span>
        </h2>
    </div>

Can anyone help me out with this... I tried with the below code but not working:

import bs4 as bs
import urllib.request as url
import requests

source = url.urlopen('https://www.facebook.com/events/777016493046448/')
soup = bs.BeautifulSoup(source, 'html.parser')

result = soup.find('span', attrs={'class':'d2edcug0 hpfvmrgz qv66sw1b c1et5uql rrkovp55 a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v hnhda86s jdix4yx3 hzawbc8m'}).text

print(result)
question from:https://stackoverflow.com/questions/65940094/how-to-scrape-the-event-details-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Chrome('C:chromedriver_win32chromedriver.exe')
driver.get('https://www.facebook.com/events/777016493046448/')
html = driver.page_source

soup = BeautifulSoup(html, 'html.parser')
result = soup.find('div', class_=['2ycp', '_5xhk'])
print(result.text)
driver.close()

You also need to install chromedriver and it to path.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...