How to scrape javascript website with Python?
I am trying to crawl a website. I've tried using both methods, but neither gives me the full website source code I'm looking for. I am trying to scrape news headlines from the website url provided below.
Website: "https://www.todayonline.com/"
Here are the two methods I tried and failed.
Method One: Beautiful Soup
tdy_url = "https://www.todayonline.com/" page = requests.get(tdy_url).text soup = beautifulsoup(page) soup # returns me a html with javascript text soup.find_all('h3') ### returns me empty list []
Method 2: selenium beautifulsoup
tdy_url = "https://www.todayonline.com/" options = Options() options.headless = True driver = webdriver.Chrome("chromedriver",options=options) driver.get(tdy_url) time.sleep(10) html = driver.page_source soup = BeautifulSoup(html) soup.find_all('h3') ### Returns me only less than 1/4 of the 'h3' tags found in the original page source
please help. I've tried scraping other news sites and this is much easier. Thanks.
Correct answer
You can access the data through the api (look at the Network tab):
For example,
import requests url = "https://www.todayonline.com/api/v3/news_feed/7" data = requests.get(url).json()
The above is the detailed content of How to scrape javascript website with Python?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Python and WebDriver extension: Simulating mouse wheel operations in web pages Introduction: With the continuous development of web interaction design, simulating user operations has become more and more important in automated testing. On some web pages, the use of the mouse wheel has become one of the common operations. However, for developers who use Python to write automated test scripts, how to simulate mouse wheel operations in WebDriver can become a challenge. This article will introduce a method using Python and WebDriv

Use Python and WebDriver to screenshot web pages and save them as PDF files Summary: During web development and testing, it is often necessary to screenshot web pages for analysis, recording, and reporting. This article will introduce how to use Python and WebDriver to take screenshots of web pages and save the screenshots as PDF files for easy sharing and archiving. 1. Install and configure SeleniumWebDriver: Install Python: Visit the Python official website (https:

Use Python and WebDriver to automatically fill in verification codes on web pages. With the development of the Internet, more and more websites have introduced verification code mechanisms in user registration, login and other operations to improve security and prevent automated attacks. However, manually entering the verification code is not only troublesome, but also increases the complexity of the user experience. So, is there a way to automatically fill in the verification code? The answer is yes. This article will introduce how to use Python and WebDriver to automatically fill in verification codes on web pages. firstly, I

Using Python and WebDriver to implement automatic web page refresh Introduction: In daily web browsing, we often encounter scenarios that require frequent web page refreshes, such as monitoring real-time data, automatically refreshing dynamic pages, etc. Manually refreshing the web page will waste a lot of time and energy, so we can use Python and WebDriver to implement the function of automatically refreshing the web page and improve our work efficiency. 1. Installation and configuration environment Before starting, we need to install and configure the corresponding environment. Install Python

Using Python and WebDriver to automatically fill in form data on web pages is an important part of the software development process. One of them is the automatic filling of web forms. For developers, filling out forms manually is a tedious and error-prone process. Using Python and WebDriver to automatically fill in table data during the automatic testing process can reduce manual duplication of work and improve testing efficiency. In this article, I will introduce how to use Selenium with Python

Python and WebDriver extensions: Simulate right-click mouse clicks on web pages When using Python and WebDriver for automated web page testing, we often need to simulate user mouse behaviors, such as clicks, drags, and right-click menu operations. WebDriver will provide some basic mouse action functions, such as click, drag_and_drop, etc., but it does not directly provide a function to simulate a right mouse click. This article will introduce how to use Python and WebD

Use Python and WebDriver extensions to automate the drag-and-drop operation of web pages. In actual web applications, drag-and-drop (Drag and Drop) is a common interactive operation, which can enhance user experience and convenience. Automating drag-and-drop operations for web pages is an important and common task for testers. This article will introduce how to use Python and WebDriver extensions to automate drag-and-drop operations on web pages. 1. Preparation Before starting, we need to install Pyt

Using Python and WebDriver to implement form automatic filling function In daily website browsing, we often encounter situations where we need to fill in forms. When we need to fill out the same or similar forms frequently, manual filling becomes tedious and time-consuming. Fortunately, we can use Python and WebDriver to realize the function of automatically filling in forms and improve our work efficiency. First, we need to install the selenium library. Selenium is an automated testing tool that can simulate
