1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

知財のあれこれをPythonで何とかする

Posted at

クリップボードから必要な情報だけを抜き出してペーストする

例としてJ-platpatのOPDのページからJP,USの登録番号だけを抜き出してみます。

(準備)

ライブラリをインストールする(pip install pyperclip)。
後述のProgram1をファイル名program1.pyで保存。

(操作方法)

手順1.J-platpatで何かの特許番号を入力し「OPD」ボタンをクリックしOPDのファミリ表示ページを開く。
1.png
手順2.Ctrl+A(全選択)→Ctrl+C(コピー)でファミリ表示ページ内の全文字情報をクリップボードにとりこむ。
2.png

手順3.準備のステップで作成したProgram1.pyをダブルクリックして実行する。
(実行する前にクリップボードをクリアしないでください)
4.png

手順4.所望のアプリケーション(メモ帳やExcel)にペースト(Ctrl+V)する。

手順1.~4.を行うと、OPDのファミリ表示ページ内の文字列の内、JPとUSの登録番号だけがペーストできます。

(メモ帳にペーストした例)
3.png

プログラムは以下のようになります。

Program1.py
import pyperclip
import re

# クリップボードから文字列を変数textに取り込む
text = pyperclip.paste()

# 不用な文字(改行、■)を削除
text = text.replace('\n', '').replace('\r', '').replace('', '')

# JPとUSの登録番号を抽出
idg1='\r\n'.join(re.findall("JP.[0-9]{7}.B[1-2]", text))
idg2='\r\n'.join(re.findall("US.[0-9]{7,8}.B[1-2]", text))
idg3='\r\n'.join(re.findall("US.RE[0-9]{5}.E", text))

# 不用な文字(.)を削除する
text2=""
for idg in [idg1, idg2, idg3]:
    idg = idg.replace('.', '')
    text2=text2+idg+'\r\n'

# クリップボードにはりつけ
pyperclip.copy(text2)

プログラムのポイント

今回のプログラムではpythonの機能のうち
クリップボードから文字列を取り込む→ text = pyperclip.paste()
文字列をクリップボードにはりつける→ pyperclip.copy(text2)
を利用しています。

応用

EPやCNを抽出したい場合以下のコマンドを追加してください。

Program2.py
idg4='\r\n'.join(re.findall("EP.[0-9]{7}.B[1-2]", text))
idg5='\r\n'.join(re.findall("CN.[0-9]{9}.[BC]", text))

以下の行は書き換えが必要です
for idg in [idg1, idg2, idg3]:for idg in [idg1, idg2, idg3, idg4, idg5]:

最後に

知財業務の省力化にあたりPythonとVBAのどちらでも実現できることは多いと思います。PythonにできてVBAでできないことは何だろう?と考えていたら、キー操作に関する部分はPythonしかできないのでは思い、コピペ作業の省力化を思いつきました。
(後で調べたらVBAでも可能なようですがかなり手順が多い模様。)
今回の記事が何らかの助けになれば幸いです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?