print(tree.xpath('//div[@class="center-stack"]//*/a[@class="name"]/@href'))
你是缺少一個右"center-stack"
後]
。
你也可以拉a[@class="name"]
標籤從div[@class="content"]
tree.xpath('//div[@class="content"]//a[@class="name"]/@href')
都將給你的HREFs你想:
In [19]: import requests
In [20]: from lxml.html import fromstring
In [21]: r = requests.get("https://itunes.apple.com/us/app/candy-crush-saga/id553834731")
In [22]: tree = fromstring(r.content)
In [23]: a = tree.xpath('//div[@class="content"]//a[@class="name"]/@href')
In [24]: b = tree.xpath('//div[@class="center-stack"]//*/a[@class="name"]/@href')
In [25]: print(a == b)
True
In [26]: print(a)
['https://itunes.apple.com/us/app/word-search-puzzles/id609067187?mt=8', 'https://itunes.apple.com/us/app/cookie-jam/id727296976?mt=8', 'https://itunes.apple.com/us/app/jewel-mania/id561326449?mt=8', 'https://itunes.apple.com/us/app/jelly-splash/id645949180?mt=8', 'https://itunes.apple.com/us/app/bubble-island/id531354582?mt=8']
In [27]: print(b)
['https://itunes.apple.com/us/app/word-search-puzzles/id609067187?mt=8', 'https://itunes.apple.com/us/app/cookie-jam/id727296976?mt=8', 'https://itunes.apple.com/us/app/jewel-mania/id561326449?mt=8', 'https://itunes.apple.com/us/app/jelly-splash/id645949180?mt=8', 'https://itunes.apple.com/us/app/bubble-island/id531354582?mt=8']
使用什麼樣的教程是....只是想知道 – danidee
1 )請隔離錯誤的行爲,並提供代碼 2)你想在教程 – selyunin
中實現什麼你不關閉方括號 – splash58