This is my html –
JavaScript
x
8
1
<html>
2
<body>
3
<img src="https://example.com/staks.jpg">
4
<a href="https://example.com">Link1</a>
5
<a href="https://example.com/page2">Link2</a>
6
</body>
7
</html>
8
I want to get url of Link1 with python as a variable –
JavaScript
1
10
10
1
import requests
2
import re
3
4
r = requests.get("https://myUrlExample.com")
5
s = r.text
6
pattern = re.compile("""href="https://""") # i don't know what pattern should i put
7
matches = re.findall(pattern, s)
8
if len(matches) > 0:
9
print(matches[0])
10
Advertisement
Answer
Actaually i found this using github copilot –
JavaScript
1
4
1
s = r.text
2
patter = r'href="https://(.*?)"'
3
url = re.findall(pattern, s)
4