Pythonの自動検索(地域の個人的ニュース)

ホームページ制作

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

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


【自動検索のコード】

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()
Translate »