回答編集履歴

2

追記

2019/07/24 08:17

投稿

yambejp
yambejp

スコア114583

test CHANGED
@@ -41,3 +41,51 @@
41
41
  </script>
42
42
 
43
43
  ```
44
+
45
+
46
+
47
+ # 追記
48
+
49
+ ```javascript
50
+
51
+ $(function(){
52
+
53
+ $.ajax({
54
+
55
+ url:"http://exsample.com",
56
+
57
+ dataType:"html",
58
+
59
+ }).done(function(html){
60
+
61
+ var want=$(html).filter('.fuga').map(function(){return $(this).attr('href');}).get();
62
+
63
+ console.log(want);
64
+
65
+ });
66
+
67
+ });
68
+
69
+ ```
70
+
71
+
72
+
73
+ - exsample.com
74
+
75
+ ```HTML
76
+
77
+ <html>
78
+
79
+ <body>
80
+
81
+ <a href="aaa.html" class="hoge">hoge</div>
82
+
83
+ <a href="bbb.html" class="hoge fuga">hoge fuga</div>
84
+
85
+ <a href="ccc.html" class="fuga">fuga</div>
86
+
87
+ </body>
88
+
89
+ </html>
90
+
91
+ ```

1

chousei

2019/07/24 08:16

投稿

yambejp
yambejp

スコア114583

test CHANGED
@@ -5,3 +5,39 @@
5
5
  そうでなければアクセス先ではCORSの制約でソースを取得できないように
6
6
 
7
7
  している=つまりアクセスを許可していないと理解できます
8
+
9
+
10
+
11
+ # sample
12
+
13
+ ajaxで外からhtmlを取得できるなら
14
+
15
+ ```javascript
16
+
17
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
18
+
19
+ <script>
20
+
21
+ $(function(){
22
+
23
+ $.ajax({
24
+
25
+ url:"http://exsample.com",
26
+
27
+ dataType:"html",
28
+
29
+ }).done(function(html){
30
+
31
+ var want=$(html).filter('.fuga').map(function(){return $(this).text();}).get();
32
+
33
+ console.log(want);
34
+
35
+ });
36
+
37
+
38
+
39
+ });
40
+
41
+ </script>
42
+
43
+ ```