-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxpath.py
More file actions
23 lines (21 loc) · 722 Bytes
/
xpath.py
File metadata and controls
23 lines (21 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
from lxml import etree
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36'
}
text = requests.get('https://maoyan.com/board/4', headers=headers).text
html = etree.HTML(text)
array = html.xpath('//dd')
print(array)
for item in array:
content = etree.tostring(item).decode('utf-8')
temp = etree.HTML(content)
results = temp.xpath(
'//img/@data-src|'
+ '//p[@class="name"]/a/text()|'
+ '//p[@class="star"]/text()|'
+ '//p[@class="releasetime"]/text()|'
+ '//i[@class="integer"]/text()|'
+ '//i[@class="fraction"]/text()'
)
print(results)