teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追記

2019/07/24 08:17

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -19,4 +19,28 @@
19
19
 
20
20
  });
21
21
  </script>
22
+ ```
23
+
24
+ # 追記
25
+ ```javascript
26
+ $(function(){
27
+ $.ajax({
28
+ url:"http://exsample.com",
29
+ dataType:"html",
30
+ }).done(function(html){
31
+ var want=$(html).filter('.fuga').map(function(){return $(this).attr('href');}).get();
32
+ console.log(want);
33
+ });
34
+ });
35
+ ```
36
+
37
+ - exsample.com
38
+ ```HTML
39
+ <html>
40
+ <body>
41
+ <a href="aaa.html" class="hoge">hoge</div>
42
+ <a href="bbb.html" class="hoge fuga">hoge fuga</div>
43
+ <a href="ccc.html" class="fuga">fuga</div>
44
+ </body>
45
+ </html>
22
46
  ```

1

chousei

2019/07/24 08:16

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -1,4 +1,22 @@
1
1
  URL先にajaxでアクセスできるか、jsonpなどでhtml情報を返してくれる
2
2
  APIを用意してもらってください
3
3
  そうでなければアクセス先ではCORSの制約でソースを取得できないように
4
- している=つまりアクセスを許可していないと理解できます
4
+ している=つまりアクセスを許可していないと理解できます
5
+
6
+ # sample
7
+ ajaxで外からhtmlを取得できるなら
8
+ ```javascript
9
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
10
+ <script>
11
+ $(function(){
12
+ $.ajax({
13
+ url:"http://exsample.com",
14
+ dataType:"html",
15
+ }).done(function(html){
16
+ var want=$(html).filter('.fuga').map(function(){return $(this).text();}).get();
17
+ console.log(want);
18
+ });
19
+
20
+ });
21
+ </script>
22
+ ```