项目介绍

oxylabs/google-news-scraper 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,目前获得 3.4k 个 Star、30 次 Fork。

仓库全名
oxylabs/google-news-scraper
Star 数
3.4k
Fork 数
30
未关闭 Issue
6

README 摘要

Scraping Google News Free Google News Scraper Prerequisites Installation Getting the topic to scrape Scraping Notes Oxylabs Google News Scraper API Request sample Free Google News Scraper Prerequisites To run this tool, you need to have Python 3.11 installed in your system. Installation Open up a terminal window, navigate to this repository and run this command: make install Getting the topic to scrape This tool is…

完整内容见 GitHub 原始 README 或本页 。

常见问题

google-news-scraper 用什么语言开发?

主要使用 Python 编写,目前有 3.4k 个 Star。

如何获取 google-news-scraper 的源码?

可以直接克隆仓库:git clone https://github.com/oxylabs/google-news-scraper.git;安装与运行步骤见仓库 README。

google-news-scraper 最近还在维护吗?

仓库最近一次更新为 6月8日,当前有 6 个未关闭 Issue;Star 数为 3.4k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Use Google News Scraper API to obtain the latest global news for your project, including a wide range of sources, headlines, URLs, and publication dates from the Google News platform.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Makefile
Python

README

Scraping Google News

Oxylabs promo code

YouTube

Free Google News Scraper

Prerequisites

To run this tool, you need to have Python 3.11 installed in your system.

Installation

Open up a terminal window, navigate to this repository and run this command:

make install

Getting the topic to scrape

This tool is used to scrape Google News articles based on the topic they’re listed in.

First of all, open up Google News, and look through the topics listed in the top header of the webpage.

image

Click on a topic you wish to scrape. In this example we’ll be using the Business topic.

Next, look at the URL in your browser and copy the string of characters that come after /topics/, that’s your topic ID.

image

In the URL shown in the screenshot, the topic ID would be CAAqJggKIiBDQkFTRWdvSUwyMHZNRGx6TVdZU0FtVnVHZ0pWVXlnQVAB.

Save this value, you’ll need it for scraping the articles.

Scraping

To scrape articles from your selected topic, run this command in your terminal: make scrape TOPIC_ID=<your_selected_topic_id>

With the Business topic ID selected before, the command should look like this:

make scrape TOPIC_ID=CAAqJggKIiBDQkFTRWdvSUwyMHZNRGx6TVdZU0FtVnVHZ0pWVXlnQVAB

After running the command, you should see this in your terminal:

image

When the tool has finished running, you should see a file named articles.csv in the directory you were running the tool.

If you open the generated CSV file, the data should look something like this:

image

Notes

In case the code doesn’t work or your project is of bigger scale, please refer to the second part of the tutorial. There, we showcase how to scrape public data with Oxylabs Scraper API.

Oxylabs Google News Scraper API

You can take a free trial for Google News API (part of the Oxylabs all-in-one Web Scraper API) and get up to 2K free results. The tool will deliver a list of sources, titles, URLs, and dates from published articles all over the Google News portal. It utilizes a fast-adapting infrastructure to manage proxies, access web data, and parsing automatically, so you can focus on data processing instead of scraper maintenance.

After you claim your trial, using Google News Scraper API consists of three main steps:

  1. Create your API user via our dashboard
  2. Send a request
  3. Retrieve the data in JSON, HTML, or Markdown

Request sample

In the examples below, we make a request to obtain News search result pages for the search term adidas.

import requests
from pprint import pprint

# Structure payload.
payload = {
    'source': 'google_search',
    'query': 'adidas',
    'parse': True,
    'context': [
        {'key': 'udm', 'value': '12'},
    ],
}

# Get response.
response = requests.post(
    'https://realtime.oxylabs.io/v1/queries',
    auth=('USERNAME', 'PASSWORD'),
    json=payload,
)

# Print prettified response to stdout.
pprint(response.json())

To see request samples in other languages and parameter values along with their descriptions, please take a look at our extensive Google News API documentation.

Read More Google Scraping Related Repositories: Google Sheets for Basic Web Scraping, Google Play Scraper, How To Scrape Google Jobs, How to Scrape Google Scholar, How to Scrape Google Flights with Python, How To Scrape Google Images, Scrape Google Search Results, Scrape Google Trends

评论

暂无评论