Last active
January 29, 2024 17:53
-
-
Save amberj/18ed707af8a4a4470db15919640c1cfb to your computer and use it in GitHub Desktop.
Beautiful Soup Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
from curl_cffi import requests | |
from bs4 import BeautifulSoup | |
''' | |
requirements.txt | |
beautifulsoup4==4.12.2 | |
certifi==2023.7.22 | |
cffi==1.15.1 | |
charset-normalizer==3.2.0 | |
curl-cffi==0.5.9 | |
idna==3.4 | |
pycparser==2.21 | |
requests==2.31.0 | |
soupsieve==2.5 | |
urllib3==2.0.5 | |
''' | |
url = "https://www.tanishq.co.in/gold-rate.html" | |
r = requests.get(url, impersonate="chrome110") | |
soup = BeautifulSoup(r.text, 'html.parser') | |
# To extract this: | |
# | |
# 6,152 | |
# | |
# from: | |
# | |
# <span data-lfr-editable-id="1-todayprice" data-lfr-editable-type="rich-text">6,152</span> | |
t = soup.find("span", attrs={"data-lfr-editable-id": "1-todayprice"}).text | |
print(t) | |
# To find: | |
# | |
# <span class="resend-otp-timer" id="out">00:30</span> | |
mydivs = soup.find_all("span", {"class": "resend-otp-timer"}) | |
print(mydivs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment