17

我正在为不同的新闻媒体创建一个网络爬虫,对于《纽约时报》和《卫报》来说,这很容易,因为他们有自己的 API。

现在,我想从这家报纸 GulfTimes.com 上抓取结果。他们没有在他们的网站上提供高级搜索,所以我求助于谷歌新闻。但是,Google 新闻 Api 已被弃用。我想要的是从高级搜索中检索结果的数量,例如关键字 =“埃及”和 begin_date="10/02/2011" 和 end_date="10/05/2011"。

这在 Google 新闻 UI 中是可行的,只需将源设置为“Gulf Times”以及相应的查询和日期,并简单地手动计算结果的数量,但是当我尝试使用 python 执行此操作时,我得到一个 403 错误,这是可以理解的.

关于我将如何做到这一点的任何想法?或者除了谷歌新闻之外还有其他服务可以让我这样做吗?请记住,我会一次发出近 500 个请求。

import json
import urllib2
import cookielib
import re
from bs4 import BeautifulSoup


def run():
   Query = "Egypt"
   Month = "3"
   FromDay = "2"
   ToDay = "4"
   Year = "13"
   url='https://www.google.com/search?pz=1&cf=all&ned=us&hl=en&tbm=nws&gl=us&as_q='+Query+'&as_occt=any&as_drrb=b&as_mindate='+Month+'%2F'+FromDay+'%2F'+Year+'&as_maxdate='+Month+'%2F'+ToDay+'%2F'+Year+'&tbs=cdr%3A1%2Ccd_min%3A3%2F1%2F13%2Ccd_max%3A3%2F2%2F13&as_nsrc=Gulf%20Times&authuser=0'
   cj = cookielib.CookieJar()
   opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
   request = urllib2.Request(url)   
   response = opener.open(request)
   htmlFile = BeautifulSoup(response)
   print htmlFile


run()
4

3 回答 3

20

您可以使用很棒的请求库:

import requests

URL = 'https://www.google.com/search?pz=1&cf=all&ned=us&hl=en&tbm=nws&gl=us&as_q={query}&as_occt=any&as_drrb=b&as_mindate={month}%2F%{from_day}%2F{year}&as_maxdate={month}%2F{to_day}%2F{year}&tbs=cdr%3A1%2Ccd_min%3A3%2F1%2F13%2Ccd_max%3A3%2F2%2F13&as_nsrc=Gulf%20Times&authuser=0'


def run(**params):
    response = requests.get(URL.format(**params))
    print response.content, response.status_code


run(query="Egypt", month=3, from_day=2, to_day=2, year=13)

你会得到 status_code=200。

而且,顺便说一句,看看scrapy项目。没有什么比这个工具更简单了。

于 2013-03-21T15:48:10.247 回答
4

您可以使用google-search-results包从 Google 新闻中提取数据。这是一个免费试用的付费 API。

在 Repl.it 上查看演示

from serpapi import GoogleSearch
import os

month = 4
from_day = 2
to_day = 3
year = 2020

params = {
    "engine": "google",
    "q": "Trump",
    "google_domain": "google.com",
    "tbm": "nws",
    "tbs": f"cdr:1,cd_min:{month}/{from_day}/{year},cd_max:{month}/{to_day}/{year}",
    "api_key": os.getenv("API_KEY"),
}

client = GoogleSearch(params)
data = client.get_dict()

print(f"Raw HTML: {data['search_metadata']['raw_html_file']}")
print(f"JSON endpoint: {data['search_metadata']['json_endpoint']}")
print()

print("News results")

for result in data['news_results']:
    print(f"""
Title: {result['title']}
Snippet: {result['snippet']}
Date: {result['date']}
""")

JSON 响应的一部分

{
  "news_results": [
    {
      "position": 1,
      "title": "Trump Promotes Oil Deal That May Not Exist",
      "link": "https://www.nytimes.com/2020/04/02/us/politics/trump-russia-saudi-arabia-oil.html",
      "source": "The New York Times",
      "date": "15 hours ago",
      "snippet": "WASHINGTON — When oil prices crashed in early March after a dispute between \nRussia and Saudi Arabia, President Trump put a positive spin on the news.",
      "thumbnail": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAHAAcAMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAACBAEDBQAGB//EADkQAAIBAwMCAgcHAwMFAAAAAAECAwAEEQUSITFBE1EGFCJhcYGhIzJSkbHB8EJi0ST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KCziEOnDO3P2h7E8Z95+WPdUm++iqXXZgNCR1FQjPE2Y2ZD5qauZ/PgeVVN76oTHIdZv4eFuGYf3AGm4fSOVT9rCjeZHFY4GTUOoFI8cX8Dqclpnp4fSOE9WeM+8E4rRg1RJipV0lI9wzXhgfLiiVipz0NTl/ni9FFnktnujPCWBliiJx/UmQKlrlW2Zdtq5wAOPhXlbTU5YsLI3iL7+v51rxSwzoHTB+hFQlj47LRyXo0knt1fduXd2O0ZFYtpbxQ+ll1f2l2zXXiKJYmjARYmABGc8kAdseVPDlccMPI813gJjIDRnzVyPpWUXG6ZnJOrP//Z"
    },
    {
      "position": 2,
      "title": "Trump’s Oil Summit",
      "link": "https://www.wsj.com/articles/trumps-oil-summit-11585870063",
      "source": "Wall Street Journal",
      "date": "Opinion · 16 hours ago",
      "snippet": "Trump's Oil Summit. Tariffs and quotas won't solve a price shock caused by \na pandemic and a Saudi Arabia-Russia feud.",
      "thumbnail": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAHAAcAMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAAFBgIDBAABB//EADwQAAIBAgQEBAQDBgQHAAAAAAECAwQRAAUSIRMxQVEGFCJhMnGBkRWhwSNCYrHR8AczUnIWJEOCksLx/8QAFwEBAQEBAAAAAAAAAAAAAAAAAQACA//EABsRAQEBAAMBAQAAAAAAAAAAAAARARIhMQJB/9oADAMBAAIRAxEAPwD6D5od8d5od8LhrnFzwGAHMkMAMQ/EVbkQD21Y6RjkZ/NjvjvNjvhX/EQote56bnHLX3Nhc/fbBFyNHmx3x55s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E3H0/v8APEGqPJvFJTwhXVSole+mx5owFtj2PfAd5X4jeXV0jvdQz2P2AOI8Wqv6XVQOlzy7dMWYt2nnMfHEs/h4ZXUQRywstmM6F2W3JQwYcjuG58vqs1OeZhKlCxZf+Uplp0G+hkW+5UmxJvvgaaio06ZArqeg3t9CcTR4HYIYmueRjNifof0xrexnT//Z"
    }
  ]
}

输出

News results

Title: Trump Promotes Oil Deal That May Not Exist
Snippet: WASHINGTON — When oil prices crashed in early March after a dispute between 
Russia and Saudi Arabia, President Trump put a positive spin on the news.
Date: 15 hours ago


Title: Trump’s Oil Summit
Snippet: Trump's Oil Summit. Tariffs and quotas won't solve a price shock caused by 
a pandemic and a Saudi Arabia-Russia feud.
Date: Opinion · 16 hours ago


Title: OPEC and allies reportedly set for video meeting as analysts pour 
skepticism on Trump's intervention
Snippet: “Donald Trump's tweet … It's nonsense, really,” Patrick Armstrong, chief 
investment officer at Plurimi Investment Managers, told CNBC's “Squawk Box 
Europe” on ...
Date: 5 hours ago


Title: Trump again tests negative for coronavirus
Snippet: President Donald Trump on Thursday again tested negative for the 
coronavirus after being tested by the White House physician, according to 
two White House ...
Date: 17 hours ago


Title: Trump passes the buck as deadly ventilator shortage looms
Snippet: (CNN) President Donald Trump is pinning the blame on states for a shortage 
of ventilators that governors warn could effectively condemn coronavirus 
patients to ...
Date: 10 hours ago

如果您想了解更多信息,请查看SerpApi 文档live playground

SerpApi 谷歌新闻

披露:我为 SerpApi 工作。

于 2020-04-03T16:06:46.650 回答
3

嗨,你可以用简单的方法像这样报废

from bs4 import BeautifulSoup
import requests

url="https://news.google.co.in/"
code=requests.get(url)
soup=BeautifulSoup(code.text,'html5lib')
for title in soup.find_all('span',class_="titletext"):
print title.text
于 2017-05-12T23:36:59.080 回答