1

I am trying to scrape all elements(Images, Graphs, Hyper Links) of this website. But, unfortunately, the images, graphs, and hyperlinks are not scraping properly. I tried using bs4.

import requests
from bs4 import BeautifulSoup

url ='https://www.gold.org/goldhub/research/investment-update-case-gold-uk-defined-benefit-schemes'

page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
lay_content = soup.find("div", {"class": "layout-content"})

In this way, the extracted contents are not getting all things. How can I do this? Thanks for reading.

2
  • There is a chance that a lot of these webpage elements are rendered a few seconds after the initial page load using JavaScript. Unfortunately the Python requests library only loads the static HTML, it doesn't wait for the JavaScript to run and load the data. I would recommend using the Python Selenium library instead of requests as it has the ability to use a browser engine to run the JavaScript and wait for the data to load. Commented Dec 13, 2022 at 14:35
  • @Tom I tried using selenium in Kaggle it doesn't work. It is easily possible using selenium in computer browser, but in my PC that is not possible due to memory issues. I am looking if there is any alternative solution. Commented Dec 13, 2022 at 14:41

1 Answer 1

1

You can use find_all() method.
When no arguments passed it will return all the elements.
So, this should give you all the elements on the page.

import requests
from bs4 import BeautifulSoup

url ='https://www.gold.org/goldhub/research/investment-update-case-gold-uk-defined-benefit-schemes'

page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
lay_content = soup.find_all()
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your effort. But In this way graphs and hyperlinks are not scrapped.
Maybe because these elements created later by some scripts? That's why Selenium may be better for such issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.