python - 谷歌搜索

我正在尝试抓取谷歌搜索,人们也在搜索链接。

例如,当您在谷歌上搜索“Christopher Nolan”时。谷歌还制作了“people also search for”,其中包括与我们的搜索相关的人物图像。在这种情况下,我们的人员也会搜索产品(Christian bale、Emma Thomas、Zack Synder 等)。我有兴趣抓取这些数据。

我正在使用 scrapy 框架并编写了一个简单的 scraper 但它返回一个空的 CSV 数据文件。以下是我到目前为止的代码,感谢您的帮助。希望我想要实现的一切都很清楚。我使用 Xpath 助手(谷歌应用程序)来帮助找到 Xpath。

我的代码:

# PyGSSpider(spidder folder)
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import Selector
from PyGoogleSearch.items import PyGSItem
import sys

class PyGSSpider(CrawlSpider):
    name = "google"
    allowed_domains = ["www.google.com"]
    start_urls = ["https://www.google.com/#q=christopher+nolan"]

    #Extracts Christopher Nolan link     
    rules = [
        Rule(SgmlLinkExtractor(allow=("https://www.google.com/search?q=christpher+noaln&oq=christpher+noaln&aqs")), follow=True),
        Rule(SgmlLinkExtractor(allow=()), callback='parse_item')
    ]
   
    #Parse function for extracting the people also search link.
    def parse_item(self,response):
        self.log('Hi, this is an item page! %s' % response.url)
        sel=Selector(response)
        item=PyGSItem()
        item['peoplealsosearchfor'] = sel.xpath('//div[@id="cnt"]/@href').extract()
       
        return item

项目.py:

from scrapy.item import Item, Field

class PyGSItem(Item):
    peoplealsosearchfor = Field()

最佳答案

这行不通的原因是 Google 实现了一种算法,该算法阻止机器人使用其搜索。

但是使用 Selenium 可能会成功。

https://stackoverflow.com/questions/23840059/

相关文章:

matlab - gnu-octave 方波载波的正弦 FM 调制

ruby-on-rails - 尝试使用 Devise 向我的用户模型添加外来关系,然后更新它

php - Laravel 存储函数更改返回数据

visual-studio-2010 - Visual Studio : show all spec

python - 如何将.html文件输出到.doc文件django

ios - Cordova - 使用固定页眉和页脚滚动 (ios)

angularjs - 是否可以在模板 Angularjs 中输出整个范围?

search - 如何让 Solr suggester 也处理拼写错误?

java - 在语言转换 java swing 应用程序中处理字符宽度

r - 传单 map 未在浏览器中显示