質問編集履歴
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,19 +44,19 @@
|
|
44
44
|
html = request.urlopen(base_url)
|
45
45
|
|
46
46
|
soup = BeautifulSoup(html,'html.parser')
|
47
|
-
|
48
|
-
|
49
|
-
wb = op.load_workbook('スクレイピング.xlsx','w')
|
50
|
-
|
47
|
+
i = 0
|
51
|
-
for
|
48
|
+
for a_tag in soup.find_all('a'):
|
52
|
-
j = (urljoin(base_url,
|
49
|
+
j = (urljoin(base_url, a_tag.get('href')))
|
53
50
|
if j.startswith('javascript'):
|
54
51
|
continue
|
55
|
-
|
52
|
+
i += 1
|
56
53
|
ws['A'+str(i)].value = j
|
57
54
|
wb.save('スクレイピング.xlsx')
|
55
|
+
|
56
|
+
|
57
|
+
|
58
58
|
```
|
59
59
|
```
|
60
|
+
s['A'+str(i)].value = j
|
60
|
-
|
61
|
+
AttributeError: 'EmptyCell' object attribute 'value' is read-only
|
61
|
-
ValueError: {0} is not a valid coordinate or range
|
62
62
|
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
以下がコードとエラーです。
|
5
5
|
ご教授お願いいたします。
|
6
6
|
```python
|
7
|
+
from urllib import request
|
8
|
+
from bs4 import BeautifulSoup
|
9
|
+
import requests
|
10
|
+
from urllib.parse import urljoin
|
11
|
+
import openpyxl as op
|
12
|
+
|
7
13
|
base_url = "url"
|
8
14
|
html = request.urlopen(base_url)
|
9
15
|
|
@@ -23,4 +29,34 @@
|
|
23
29
|
```
|
24
30
|
ws = ['A'+str(i)].value = j
|
25
31
|
AttributeError: 'list' object has no attribute 'value'
|
32
|
+
```
|
33
|
+
|
34
|
+
回答者様の回答を反映しました。
|
35
|
+
|
36
|
+
```python
|
37
|
+
from urllib import request
|
38
|
+
from bs4 import BeautifulSoup
|
39
|
+
import requests
|
40
|
+
from urllib.parse import urljoin
|
41
|
+
import openpyxl as op
|
42
|
+
|
43
|
+
base_url = "url"
|
44
|
+
html = request.urlopen(base_url)
|
45
|
+
|
46
|
+
soup = BeautifulSoup(html,'html.parser')
|
47
|
+
|
48
|
+
|
49
|
+
wb = op.load_workbook('スクレイピング.xlsx','w')
|
50
|
+
ws = wb.active
|
51
|
+
for i in soup.find_all('a'):
|
52
|
+
j = (urljoin(base_url, i.get('href')))
|
53
|
+
if j.startswith('javascript'):
|
54
|
+
continue
|
55
|
+
|
56
|
+
ws['A'+str(i)].value = j
|
57
|
+
wb.save('スクレイピング.xlsx')
|
58
|
+
```
|
59
|
+
```
|
60
|
+
raise ValueError("{0} is not a valid coordinate or range")
|
61
|
+
ValueError: {0} is not a valid coordinate or range
|
26
62
|
```
|