2017年6月9日金曜日

クローラ、スクレイピングのメモ

■Cookieの情報を使ってログイン必要なWEBページを読みたい

chromedriverを使ったら解決。Chromedriverを適当にqiitaに書いてあったコードを使って入れたら動作せず。バージョンが古かったのか、最新のものを入れたら動いた。きちんと確認しましょう。

Chromdriver起動、入力してsubmitしてログイン、
そのままURLに移動、抽出、(次のURL・・・)、保存。

出力はテキストで。
savefile = test.txt
f = open(savefile,"w")
f.write(output_string)
f.close()


■Chromdriver起動
chromeを起動して、検索文字列を入力、Submit
# tutorial from chromdriver

import time
from selenium import webdriver
driver = webdriver.Chrome('/usr/local/bin/chromedriver')  # Optional argument
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('うへへへ')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()

0 件のコメント:

コメントを投稿