top of page

Pythonでhpの内容取得ができるがGoogle検索の中身などは取れるのか?

  • hiro2studio
  • 2021年3月1日
  • 読了時間: 1分

更新日:2021年3月1日

googleの検索結果を取得する

3/1更新 ランキング取得できました〜


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 指定のURLをブラウザで開く
# Google検索結果は取得できるのか?

import webbrowser as wb
import requests
from bs4 import BeautifulSoup

#-------------------------------------------------
## main ###
#-------------------------------------------------
if __name__=='__main__':

    # 100ランク取得
    load_url = "https://www.google.co.jp/search?hl=ja&source=hp&q=携帯+格安&ie=utf-8&oe=utf-8&num=101"

    # HTML取得
    html = requests.get(load_url)
    web_data = BeautifulSoup(html.content, "html.parser")
    list = web_data.findAll(True, {'class': 'BNeawe vvjwJb AP7Wnd'})

    # ランキング表示
    cnt = 0
    for ls in list:
        a = str(ls).strip('<div class="BNeawe vvjwJb AP7Wnd">')
        result_title = a.strip('</')
        print(str(cnt) + ":" + result_title)
        cnt = cnt + 1
 
 
 

最新記事

すべて表示
PythonでYAHOO検索もスクレイピング

前回Google検索結果のTOP100取ったのでYAHOOも追加。 YAHOOは10件ずつしか取れないので注意! #!/usr/bin/env python3 # -*- coding: utf-8 -*- # 指定のURLをブラウザで開く #...

 
 
 
Pythonで指定URL開く&HTML解析

指定URLをブラウザで開き、その中身(HTML)を取得して表示する。 #!/usr/bin/env python3 # -*- coding: utf-8 -*- # 指定のURLをブラウザで開く import webbrowser as wb import...

 
 
 

Comments


記事: Blog2_Post

©2021 by 日々Python。Wix.com で作成されました。

bottom of page