質問編集履歴
5
【試したこと】③を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -57,5 +57,14 @@
|
|
57
57
|
|
58
58
|
C:\Users\●●●●●>
|
59
59
|
|
60
|
+
⓷上記⓵⓶について ファイル名を 'lucky.py'から'11-5-lucky.py'に変更
|
61
|
+
(作業後のコマンドプロンプトのインプットとアウトプット)
|
62
|
+
C:\Users\●●●●●>AppData\Local\Programs\Python\Python38-32\Scripts\11-5-lucky.py 'Shohei Ohtani'
|
63
|
+
Googling...
|
64
|
+
|
65
|
+
C:\Users\●●●●●>
|
66
|
+
|
67
|
+
(上記⓶同様エラーメッセージも出ないが、Web頁も開かれない)
|
68
|
+
|
60
69
|
以上、長々と失礼しますが、よろしくお願いします。
|
61
70
|
takaoioi1
|
4
```Python (改行)#!python3 及び ('href')) (改行) ``` としました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,10 +14,11 @@
|
|
14
14
|
https://github.com/oreilly-japan/automatestuff-ja/blob/master/ch11/lucky.py
|
15
15
|
|
16
16
|
【自身の入力コード】
|
17
|
+
```python
|
17
|
-
|
18
|
+
#! python3
|
18
19
|
|
19
20
|
import requests, sys, webbrowser, bs4
|
20
|
-
print('Googling...')
|
21
|
+
print('Googling...')
|
21
22
|
res = requests.get('http://google.com/search?q' + ' '.join(sys.argv[1:]))
|
22
23
|
res.raise_for_status()
|
23
24
|
|
@@ -26,7 +27,8 @@
|
|
26
27
|
|
27
28
|
num_open = min(5, len(link_elems))
|
28
29
|
for i in range(num_open):
|
29
|
-
webbrowser.open('http://google.com' + link_elems[i].get('href'))
|
30
|
+
webbrowser.open('http://google.com' + link_elems[i].get('href'))
|
31
|
+
```
|
30
32
|
|
31
33
|
【保存場所・ファイル名その1】
|
32
34
|
"11-5-lucky.py"というファイル名でデスクトップのPython Scriptフォルダに保存
|
3
Pythonコードの前後に```三つおきました。コード中のコメント#を削除しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,19 +14,16 @@
|
|
14
14
|
https://github.com/oreilly-japan/automatestuff-ja/blob/master/ch11/lucky.py
|
15
15
|
|
16
16
|
【自身の入力コード】
|
17
|
-
```python #! python3
|
17
|
+
```python #! python3
|
18
|
-
# lucky.py - Google の検索結果をいくつか開く
|
19
18
|
|
20
19
|
import requests, sys, webbrowser, bs4
|
21
20
|
print('Googling...') #Google ページをダウンロード中にテキストを表示
|
22
21
|
res = requests.get('http://google.com/search?q' + ' '.join(sys.argv[1:]))
|
23
22
|
res.raise_for_status()
|
24
23
|
|
25
|
-
#TODO: 上位の検索結果のリンクを取得する
|
26
24
|
soup = bs4.BeautifulSoup(res.text,"html.parser")
|
27
25
|
link_elems = soup.select('.r a')
|
28
26
|
|
29
|
-
#TODO: 各結果のブラウザをタブで開く
|
30
27
|
num_open = min(5, len(link_elems))
|
31
28
|
for i in range(num_open):
|
32
29
|
webbrowser.open('http://google.com' + link_elems[i].get('href'))```
|
2
Python コードの前後にバッククオート3つ置きました
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
https://github.com/oreilly-japan/automatestuff-ja/blob/master/ch11/lucky.py
|
15
15
|
|
16
16
|
【自身の入力コード】
|
17
|
-
|
17
|
+
```python #! python3
|
18
18
|
# lucky.py - Google の検索結果をいくつか開く
|
19
19
|
|
20
20
|
import requests, sys, webbrowser, bs4
|
@@ -29,7 +29,7 @@
|
|
29
29
|
#TODO: 各結果のブラウザをタブで開く
|
30
30
|
num_open = min(5, len(link_elems))
|
31
31
|
for i in range(num_open):
|
32
|
-
webbrowser.open('http://google.com' + link_elems[i].get('href'))
|
32
|
+
webbrowser.open('http://google.com' + link_elems[i].get('href'))```
|
33
33
|
|
34
34
|
【保存場所・ファイル名その1】
|
35
35
|
"11-5-lucky.py"というファイル名でデスクトップのPython Scriptフォルダに保存
|
1
pythonコードの前後にバックオート三つ置きました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
https://github.com/oreilly-japan/automatestuff-ja/blob/master/ch11/lucky.py
|
15
15
|
|
16
16
|
【自身の入力コード】
|
17
|
-
#! python3
|
17
|
+
'''python #! python3
|
18
18
|
# lucky.py - Google の検索結果をいくつか開く
|
19
19
|
|
20
20
|
import requests, sys, webbrowser, bs4
|
@@ -29,7 +29,7 @@
|
|
29
29
|
#TODO: 各結果のブラウザをタブで開く
|
30
30
|
num_open = min(5, len(link_elems))
|
31
31
|
for i in range(num_open):
|
32
|
-
webbrowser.open('http://google.com' + link_elems[i].get('href'))
|
32
|
+
webbrowser.open('http://google.com' + link_elems[i].get('href'))'''
|
33
33
|
|
34
34
|
【保存場所・ファイル名その1】
|
35
35
|
"11-5-lucky.py"というファイル名でデスクトップのPython Scriptフォルダに保存
|