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

回答編集履歴

1

補足

2021/06/20 09:56

投稿

otn
otn

スコア86354

answer CHANGED
@@ -2,20 +2,21 @@
2
2
 
3
3
  そのパスは`/`で始まっているので絶対パスです。
4
4
  ただし、スキーム(`http:`や`https:`)で始まっていないので相対URLと言います。
5
+ スキームで始まるのが絶対URLです。
5
6
 
6
7
 
7
- そのページのURLを`url_of_this_page`とすると、
8
+ 絶対URLは、そのページの絶対URLを`url_of_this_page`とすると、
8
9
  ```Python
9
10
  import urllib
10
11
  ~~~
11
- target_url = urllib.parse.urljoin(url_of_this_page,element.get_attribute("href"))
12
+ target_url = urllib.parse.urljoin(url_of_this_page, element.get_attribute("href"))
12
13
  ```
13
14
  で、求まります。
14
15
 
15
16
  ```Python
16
- urllib.parse.urljoin("https://www.example.com/foo/bar.html","/a/b/c.html")
17
+ urllib.parse.urljoin("https://www.example.com/foo/bar.html", "/a/b/c.html")
17
18
  #=> 'https://www.example.com/a/b/c.html'
18
19
 
19
- urllib.parse.urljoin("https://www.example.com/foo/bar.html","./x.html")
20
+ urllib.parse.urljoin("https://www.example.com/foo/bar.html", "./x.html")
20
21
  #=> 'https://www.example.com/foo/x.html'
21
22
  ```