回答編集履歴
3
少しお行儀よく
answer
CHANGED
@@ -24,12 +24,13 @@
|
|
24
24
|
|
25
25
|
print(x, type(x))すると分かりますが、xはelement.Tag型です。
|
26
26
|
forブロックのアタマで`x = x['href']`としておけば良いかと。
|
27
|
-
|
28
|
-
あるいは、次のように書くのもアリです。
|
29
27
|
```Python
|
30
|
-
from
|
28
|
+
from time import sleep
|
31
29
|
|
30
|
+
for x in url_items:
|
32
|
-
|
31
|
+
x = x['href']
|
33
32
|
print(x, type(x))
|
34
33
|
...
|
34
|
+
|
35
|
+
sleep(1) # 相手方に負荷をかけないため
|
35
36
|
```
|
2
逃げ道作っとくやつ
answer
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
|
10
10
|
追記
|
11
11
|
---
|
12
|
+
BeautifulSoupはお試し程度にしか使ったことがないのでベストな方法ではないかもです。悪しからず。
|
13
|
+
|
12
14
|
> ```
|
13
15
|
Traceback (most recent call last):
|
14
16
|
File "base.py", line 11, in <module>
|
1
追記
answer
CHANGED
@@ -5,4 +5,29 @@
|
|
5
5
|
このようにインポートしているのですから、次のように書く必要があります。
|
6
6
|
```Python
|
7
7
|
html = req.urlopen(x)
|
8
|
+
```
|
9
|
+
|
10
|
+
追記
|
11
|
+
---
|
12
|
+
> ```
|
13
|
+
Traceback (most recent call last):
|
14
|
+
File "base.py", line 11, in <module>
|
15
|
+
html = req.urlopen(x)
|
16
|
+
File "C:\Users(※ここはユーザーネームです隠しています)\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
|
17
|
+
return opener.open(url, data, timeout)
|
18
|
+
File "C:\Users\※ここはユーザーネームです隠しています\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 521, in open
|
19
|
+
meth_name = protocol+"_request"
|
20
|
+
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
|
21
|
+
> ```
|
22
|
+
|
23
|
+
print(x, type(x))すると分かりますが、xはelement.Tag型です。
|
24
|
+
forブロックのアタマで`x = x['href']`としておけば良いかと。
|
25
|
+
|
26
|
+
あるいは、次のように書くのもアリです。
|
27
|
+
```Python
|
28
|
+
from operator import itemgetter
|
29
|
+
|
30
|
+
for x in map(itemgetter('href'), url_items):
|
31
|
+
print(x, type(x))
|
32
|
+
...
|
8
33
|
```
|