坂東市のお役立ち情報が満載!


  ホーム >> ヘッドライン >> Pythonの自動検索(地域の個人的ニュース)

ヘッドライン

  メイン  |  簡易ヘッドライン  

icon PC修理のわたなべ

Pythonの自動検索(地域の個人的ニュース) (2022-9-27 18:34:00)


sound ポッドキャスト : video/mp4

パイソンで自動検索。
プログラムのパイソンを使用し、クロームを自動的に動かしています。

ホームページのアドレスを、自動的に移動。
ペイペイのカテゴリ毎のデータが欲しかったので作りました。
これは、便利です。
パイソンは、すごすぎです!!


【自動検索のコード】

  from selenium import webdriver
from selenium.webdriver.chrome import service as fs
import time
import os
import glob
import csv

def makecategory(catnum):

    url = "https://ec-shop.net/paypay/index.php?category="+catnum
    browser.get(url)
    time.sleep(1)
    new_dir_path = 'ecshop/paypay/cat/1/2/3/4/'

    for el in browser.find_elements_by_id('cat_c'):
        print(el.get_attribute("href").strip('https://ec-shop.net/paypay/index.php?category='))
        new_file_path = new_dir_path+el.get_attribute("href").strip('https://ec-shop.net/paypay/index.php?category=')+'.csv'
        f = open(new_file_path, 'w')
        f.write(el.get_attribute("href").strip('https://ec-shop.net/paypay/index.php?category='))
        f.write(',')
        f.write(el.text)
        f.write('\n')
        f.close()

    time.sleep(1)

CHROMEDRIVER = "chromedriver.exe"
# ドライバー指定でChromeブラウザを開く
chrome_service = fs.Service(executable_path=CHROMEDRIVER)
browser = webdriver.Chrome(service=chrome_service)
browser = webdriver.Chrome(executable_path='chromedriver.exe')

files = glob.glob("ecshop/paypay/cat/1/2/3/*.csv")
for file in files:
#    print(file)
    f = open(file)
    data = csv.reader(f, delimiter=',')
    for row in data:
        print(row[0])
        makecategory(row[0])

browser.quit() 


execution time : 0.031 sec
大好評 パソコン修理ホームページ制作
坂東市観光協会 坂東市商工会 岩崎電気サービス PC修理のわたなべ クリーニング オオヤマ 坂東青年会議所 野口農園 オートショップS.S なかつま動物病院
Bando! 坂東市タウンなび