-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathht2-2.py
More file actions
31 lines (26 loc) · 1003 Bytes
/
ht2-2.py
File metadata and controls
31 lines (26 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from lxml import html
html_content = '''
<!DOCTYPE html>
<html>
<head>
<title>Search Page</title>
</head>
<body>
<form id="searchForm">
<input type="text" id="searchQuery" name="query" placeholder="Enter your search query">
<input type="text" id="regionInput" name="region" placeholder="Enter your region">
<button type="submit" id="searchButton">Search</button>
</form>
</body>
</html>
'''
# Створення дерева HTML
tree = html.fromstring(html_content)
# XPath вирази
search_query_input = tree.xpath('//input[@id="searchQuery"]')
region_input = tree.xpath('//input[@id="regionInput"]')
search_button = tree.xpath('//button[@id="searchButton"]')
# Вивід результатів
print("Search Query Input:", search_query_input[0].attrib if search_query_input else "Not found")
print("Region Input:", region_input[0].attrib if region_input else "Not found")
print("Search Button:", search_button[0].attrib if search_button else "Not found")