如何使用 GoogleScraper 包从 Python 中的不同搜索引擎中抓取 link

How to use GoogleScraper package to scrape link from different search engines in Python

我想从不同的搜索引擎中为我在 python 中的搜索查询抓取 link。

例如

查询:-“Sachin Tendulkar 是谁”

输出:link 来自 google 搜索,bing 搜索。

在挖掘了许多 link 之后,我发现 google scraper packege .

Google 刮刀 Link

https://pypi.python.org/pypi/GoogleScraper/0.1.37

但是我没有找到这个包的任何运气。任何人都可以帮我 GoogleScraper 或任何替代刮 link

嘿,您可以通过与 GoogleScraper 相同的软件包来实现它。通过 link https://github.com/NikolaiT/GoogleScraper

下面还有python代码

from GoogleScraper import scrape_with_config, GoogleSearchError
def saveLink(self, query):
        # See in the config.cfg file for possible values
        try:
            if query:
                file_name = query.replace(" " , "_")
                self.config = {
                    'SCRAPING': {
                        'use_own_ip': 'True',
                        'keyword': query,
                        'search_engines': 'bing',
                        'num_pages_for_keyword': 1,
                        'scrape_method': 'http'
                    },
                    'SELENIUM': {
                        'sel_browser': 'chrome',
                    },
                    'OUTPUT': {
                        'output_filename': "path/" + file_name + ".json"
                    },
                    'GLOBAL': {
                        'do_caching': 'False'
                    }
                }
                
                raw_html = ""
                sqlalchemy_session = scrape_with_config(self.config)
        except Exception:
            import traceback
            print(traceback.format_exc())

如果您想要重新使用多个搜索引擎,您可以添加

'search_engines': 'bing, yahoo ,google',

您将在文件 output_filename

中得到 json