Python (mechanize + BeautifulSoup) でPixivにログインしてタイトルタグの中身を取得する夢を見た

PythonでPixivにログインしてタイトルタグの中身を取得する夢を見たのでメモしておきます

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding:utf-8 -*-
import mechanize
import BeautifulSoup
 
 
username = "**************"
password = "**************"
 
br = mechanize.Browser()
br.set_handle_robots(False)
 
# ログインページを開く
br.open(login_page)
 
# ユーザ名とパスワードを指定してログイン
br.select_form(nr=1)
br["pixiv_id"] = username
br[  "pass"  ] = password
br.submit()
 
# マイページを取得
html = br.response().read()
 
# スクレイピング
soup = BeautifulSoup.BeautifulSoup(html)
recipe_title = soup.find("title")
print(recipe_title.string)
 
br.close()

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(Spamcheck Enabled)

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)