質問編集履歴
8
タグの追加
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
7
pythonコードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -28,18 +28,36 @@
|
|
28
28
|
re_pattern_img = re.compile("hoge.png")
|
29
29
|
re_pattern_start = re.compile("{")
|
30
30
|
re_pattern_end = re.compile("}")
|
31
|
+
tmp_element = ""
|
31
32
|
result = []
|
32
33
|
|
34
|
+
def is_somthing(line):
|
35
|
+
flag = False
|
36
|
+
list_except = ['}', ':']
|
37
|
+
|
38
|
+
for except_char in list_except:
|
39
|
+
if except_char not in line:
|
40
|
+
flag = True
|
41
|
+
else:
|
42
|
+
flag = False
|
43
|
+
return flag
|
44
|
+
|
45
|
+
return flag
|
46
|
+
|
33
47
|
for css_line in css_list:
|
34
48
|
found_img = re_pattern_img.search(css_line)
|
35
49
|
found_start = re_pattern_start.search(css_line)
|
36
50
|
found_end = re_pattern_start.search(css_line)
|
37
|
-
|
38
|
-
if found_start:
|
39
|
-
tmp_element = css_line.replace("{\n", "").strip()
|
40
51
|
|
52
|
+
if is_somthing(css_line):
|
53
|
+
tmp_element = tmp_element + css_line.replace("\n", "").replace("\r", "")
|
54
|
+
|
55
|
+
if found_start:
|
56
|
+
target_element = tmp_element.replace("{", "").strip()
|
57
|
+
tmp_element = ""
|
58
|
+
|
41
59
|
if found_img:
|
42
|
-
result.append(
|
60
|
+
result.append(target_element)
|
43
61
|
|
44
62
|
css_file.close()
|
45
63
|
|
6
文章の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -45,11 +45,10 @@
|
|
45
45
|
|
46
46
|
```
|
47
47
|
|
48
|
-
### 発生している問題・エラーメッセージ
|
49
|
-
まったく手に負えません。よろしくお願いします。
|
50
|
-
|
51
48
|
### 試したこと
|
49
|
+
上記の通りです。
|
52
|
-
|
50
|
+
もう少しましな、やり方があるかと思います。
|
51
|
+
ご教授いただけましたら、ありがたいです。
|
53
52
|
|
54
53
|
### 補足情報(FW/ツールのバージョンなど)
|
55
54
|
AnacondaのSpyderで作業しています。
|
5
pythonコードの更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,14 +25,15 @@
|
|
25
25
|
css_file = codecs.open(r'C:\Users\username\Desktop\test.css', 'r', 'shift_jis')
|
26
26
|
css_list = css_file.readlines()
|
27
27
|
|
28
|
+
re_pattern_img = re.compile("hoge.png")
|
29
|
+
re_pattern_start = re.compile("{")
|
30
|
+
re_pattern_end = re.compile("}")
|
31
|
+
result = []
|
32
|
+
|
28
33
|
for css_line in css_list:
|
29
|
-
re_pattern_img = re.compile("hoge.png")
|
30
|
-
re_pattern_start = re.compile("{")
|
31
|
-
re_pattern_end = re.compile("}")
|
32
34
|
found_img = re_pattern_img.search(css_line)
|
33
35
|
found_start = re_pattern_start.search(css_line)
|
34
36
|
found_end = re_pattern_start.search(css_line)
|
35
|
-
result = []
|
36
37
|
|
37
38
|
if found_start:
|
38
39
|
tmp_element = css_line.replace("{\n", "").strip()
|
4
pythonコードを更新したため。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
CSSファイル内で特定の画像を指定している要素を取得したい
|
body
CHANGED
@@ -35,7 +35,7 @@
|
|
35
35
|
result = []
|
36
36
|
|
37
37
|
if found_start:
|
38
|
-
tmp_element = css_line
|
38
|
+
tmp_element = css_line.replace("{\n", "").strip()
|
39
39
|
|
40
40
|
if found_img:
|
41
41
|
result.append(tmp_element)
|
3
pythonコードの更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,11 +22,11 @@
|
|
22
22
|
import re
|
23
23
|
import codecs
|
24
24
|
|
25
|
-
css_file = codecs.open(r'C:\Users\
|
25
|
+
css_file = codecs.open(r'C:\Users\username\Desktop\test.css', 'r', 'shift_jis')
|
26
26
|
css_list = css_file.readlines()
|
27
27
|
|
28
28
|
for css_line in css_list:
|
29
|
-
re_pattern_img = re.compile(
|
29
|
+
re_pattern_img = re.compile("hoge.png")
|
30
30
|
re_pattern_start = re.compile("{")
|
31
31
|
re_pattern_end = re.compile("}")
|
32
32
|
found_img = re_pattern_img.search(css_line)
|
@@ -36,9 +36,10 @@
|
|
36
36
|
|
37
37
|
if found_start:
|
38
38
|
tmp_element = css_line
|
39
|
-
if found_img:
|
40
|
-
print(css_line)
|
41
39
|
|
40
|
+
if found_img:
|
41
|
+
result.append(tmp_element)
|
42
|
+
|
42
43
|
css_file.close()
|
43
44
|
|
44
45
|
```
|
2
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,6 +17,32 @@
|
|
17
17
|
}
|
18
18
|
```
|
19
19
|
|
20
|
+
```python
|
21
|
+
|
22
|
+
import re
|
23
|
+
import codecs
|
24
|
+
|
25
|
+
css_file = codecs.open(r'C:\Users\da-wake\Desktop\test.txt', 'r', 'shift_jis')
|
26
|
+
css_list = css_file.readlines()
|
27
|
+
|
28
|
+
for css_line in css_list:
|
29
|
+
re_pattern_img = re.compile('hoge.png')
|
30
|
+
re_pattern_start = re.compile("{")
|
31
|
+
re_pattern_end = re.compile("}")
|
32
|
+
found_img = re_pattern_img.search(css_line)
|
33
|
+
found_start = re_pattern_start.search(css_line)
|
34
|
+
found_end = re_pattern_start.search(css_line)
|
35
|
+
result = []
|
36
|
+
|
37
|
+
if found_start:
|
38
|
+
tmp_element = css_line
|
39
|
+
if found_img:
|
40
|
+
print(css_line)
|
41
|
+
|
42
|
+
css_file.close()
|
43
|
+
|
44
|
+
```
|
45
|
+
|
20
46
|
### 発生している問題・エラーメッセージ
|
21
47
|
まったく手に負えません。よろしくお願いします。
|
22
48
|
|
1
他のユーザの参考にならない質問であるため。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
CSSファイル内で特定の画像を指定している要素を取得したい
|
1
|
+
【丸投げ質問です。】CSSファイル内で特定の画像を指定している要素を取得したい
|
body
CHANGED
File without changes
|