Program

pyppeteerでスクレイピング

Pyppeteer’s documentation — Pyppeteer 0.0.24 documentation import asyncio from pyppeteer import launch async def main(): browser = await launch() page = await browser.newPage() await page.goto('http://www.nikkei.com/markets/kabu/') element…

FC今治のゴール集計・先取点

!pip install lxml !apt install fonts-ipafont-gothic !rm /content/.cache/matplotlib/fontList.json """再起動""" import time import csv import requests from bs4 import BeautifulSoup # 試合数 n = 10 + 1 with open('fcimabari_goal.tsv', 'w') as …

PythonでスクレイピングしてテーブルをCSVに保存

Beautifulsoupの場合 import csv from bs4 import BeautifulSoup import requests url = 'http://www.example.com/' r = requests.get(url) if r.status_code == requests.codes.ok: soup = BeautifulSoup(r.content, 'html.parser') result = [[[td.get_tex…

Pandasでミニロトで遊ぶ

!pip install lxml import pandas as pd import io import requests # User-agentを設定しないとダウンロードできない url = 'http://www.japannetbank.co.jp/lottery/co/minilotojnb.csv' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64;…

石手川ダムのリアルタイムダム諸量一覧表でpandas練習

imabari.hateblo.jp !pip install lxml import pandas as pd import requests from urllib.parse import urljoin from bs4 import BeautifulSoup # 石手川ダムのリアルタイムダム諸量一覧表 url = 'http://www1.river.go.jp/cgi-bin/DspDamData.exe?ID=13680…

Colaboratoryでスクレイピング

2021/04/18現在利用できません news.mynavi.jp https://colab.research.google.com/ import pandas as pd import requests from bs4 import BeautifulSoup url = 'http://www.river.go.jp/kawabou/ipDamGaikyo.do?init=init&areaCd=88&prefCd=3801&townCd=&g…

愛媛県動物愛護センターから迷い犬猫情報を取得しTwitterに投稿

import tempfile from urllib.parse import urljoin import requests import twitter from bs4 import BeautifulSoup # 迷い犬猫情報にアクセスし、HTMLを取得する url = 'http://www.pref.ehime.jp/h25123/4415/mayoi.html' r = requests.get(url) # エラー…

herokuでtwitter botを定時実行

pipenv install python-twitter pipenv install html5lib pipenv install beautifulsoup4 pipenv install apscheduler pipenv install requests pipenv run pip freeze > requirements.txt echo "python-3.6.7" > runtime.txt echo "clock: python clock.py"…

Pythonでselenium headless(Firefox・Chrome)

Firefox github.com sudo cp geckodriver /usr/local/bin from selenium import webdriver from selenium.webdriver.firefox.options import Options from bs4 import BeautifulSoup options = Options() options.headless = True driver = webdriver.Firefo…

herokuでheaderless chromeでConnectionResetError 104

3日に1回ぐらいエラーで失敗しているので Traceback (most recent call last): File "today-hospital.py", line 17, in <module> driver = webdriver.Chrome(chrome_options=options) desired_capabilities=desired_capabilities) File "/app/.heroku/python/lib/pyt</module>…

インフルエンザによる学級閉鎖等の状況

import requests from bs4 import BeautifulSoup url = 'http://www.city.imabari.ehime.jp/gakukyou/info_influenza/' r = requests.get(url) # エラーがないか確認する if r.status_code == requests.codes.ok: soup = BeautifulSoup(r.content, 'html.par…

pythonスクレイピング関連記事

adventar.org qiita.com vaaaaaanquish.hatenablog.com orangain.hatenablog.com qiita.com qiita.com blog.mursts.jp www.yoheim.net qiita.com dev.classmethod.jp dev.classmethod.jp www.mediaplex.co.jp kiito.hatenablog.com kiito.hatenablog.com

Pythonで総選挙データのスクレイピング

データのスクレイピング AKB48総選挙データのスクレイピング import csv from urllib.request import urlopen from bs4 import BeautifulSoup url = 'http://www.akb48.co.jp/sousenkyo_45th/result.php' html = urlopen(url).read() soup = BeautifulSoup(h…

Pythonのマルチスレッドで同じものを含む順列

import concurrent.futures def permutations(head, rest): if len(rest) == 0: return [head] else: res = [] # set(集合)型で重複を削除、ソート data = sorted(set(rest)) for i in data: #配列の複製 restx = rest[:] #指定データ削除 restx.remove(i)…

蒼社川の水位をスクレイピング

import datetime import requests from bs4 import BeautifulSoup def scraping(): url = 'http://183.176.244.72/cgi/050_HQ_100_03.cgi?GID=050_HQ_100&UI=U777&SI=00000&DT=000000000000&DBDT=0000000000&MNU=1&DTO=-1&DN=0972900400025&KTM=3&GHK=3&YSK=…

PythonでRSSの新着チェック(feedparser/sqlite3)

rss_cron.pyを実行すると5分おきにrss_print.pyが実行される。 rss_cron.py from apscheduler.schedulers.blocking import BlockingScheduler import os sched = BlockingScheduler() @sched.scheduled_job('interval', minutes=5) def timed_job(): os.syst…

今治市の避難準備情報、避難勧告、避難指示情報と避難所情報をスクレイピング

import datetime import re from urllib.parse import urljoin from urllib.request import urlopen from bs4 import BeautifulSoup def get_refuge(url): html = urlopen(url).read() soup = BeautifulSoup(html, 'html.parser') title = soup.select_one('…

玉川ダムの貯水率をスクレイピング

2021/04/18現在利用できません from urllib.request import urlopen from bs4 import BeautifulSoup import datetime import csv # GRP = USR004:玉川ダム、USR005:台ダム grp = 'USR004' # KTM = 1:1時間毎、2:30分毎、3:10分毎 ktm = 1 # 現在の時刻の8分…

WindowsでHeadless Chromeでスクレイピング

qiita.com sites.google.com オプション入れてるけどバージョン59だと画面が表示される60で直るみたい # --- coding: utf-8 --- """ えひめ医療情報ネットの今治市地区の当番医案内から医療機関のリストを取得 """ import csv import re from selenium impor…

同じものを含む順列(ジェネレーター)

def permutations(data, result=[]): if not data: yield result else: for i in set(data): temp = data[:] temp.remove(i) yield from permutations(temp, result + [i]) if __name__ == '__main__': for i in permutations([1, 1, 1, 2, 2, 3]): print(i)…

Pythonで写真を集計2

import click import csv from operator import itemgetter @click.command() @click.option('--title', '-t', help='Title Mode', is_flag=True) @click.argument('input_file', type=click.File('r')) @click.argument('output_file', default='result.csv…

Pythonで写真を集計する

photo_name.csvを作成する A1 A2 A3 A4 A5 1 あいうえお かきくけこ なにぬねの あいうえお かきくけこ 2 かきくけこ たちつてと さしすせそ さしすせそ 3 さしすせそ たちつてと 4 たちつてと なにぬねの 5 なにぬねの 縦の1,2,3,4,5は人数 横のA1,A2,A3,A4…

Python 日付変換

8.1. datetime — 基本的な日付型および時間型 — Python 3.3.6 ドキュメント import datetime import time #struct_timeを変換 entry.published_parsed = time.struct_time(tm_year=2015, tm_mon=1, tm_mday=2, tm_hour=3, tm_min=4, tm_sec=5, tm_wday=4, tm…

PythonでRSS 新着チェック

import feedparser import sqlite3 from datetime import datetime URL = 'http://imabari-news.blog.so-net.ne.jp/index.xml' feedparser.USER_AGENT = 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko' fdp = feedparser.p…

kimonoでスクレイピング

Kimono : Turn websites into structured APIs from your browser in seconds kimonoで今治の不審者情報をJSON化改行と全角数字を整形 import json import urllib.request import unicodedata results = json.loads(urllib.request.urlopen("https://www.kim…

Googleニュースからリンクを作成

import feedparser from urllib.parse import parse_qs from datetime import datetime #from time import mktime url= "https://news.google.com/news/feeds?ned=us&ie=UTF-8&oe=UTF-8&q=%E4%BB%8A%E6%B2%BB&output=atom&num=30&hl=ja" #USER_AGENT変更 fee…

順列の半分

import itertools data = list(itertools.permutations([1,2,3,4,5])) n = len(data) // 2 d1 = data[:n] #リストの上半分 d2 = data[n::-1] #リストの下半分の逆順 d2.sort() #ソート for x, y in zip(d1, d2): print(x, y, end = ' ') if x == y: print('t…

同じものを含む順列(再帰)

こちらの順列を参考に同じ物を含む順列作ってみた。 Python で順列を生成 | すぐに忘れる脳みそのためのメモ def permutations(L): if L == []: return [[]] else: ret = [] # set(集合)型で重複を削除、ソート S = sorted(set(L)) for i in S: data = L[:…

同じものを含む順列

import itertools # set(集合)型で重複を削除、ソートのためリスト化 junretsu = list(set(itertools.permutations( (1, 1, 1, 2, 2, 3) ))) # ソート junretsu.sort() #順列の個数 print( len(junretsu) ) 追記リスト化してsortするよりsorted使えばよか…

Pythonでスクレイピング4(抽出)

愛媛新聞ONLINEから今治の記事のリンクを取得 import urllib.request from bs4 import BeautifulSoup from urllib.parse import urljoin def imabari_find( url ): html = urllib.request.urlopen(url).read() soup = BeautifulSoup(html, from_encoding='cp…