我正在嘗試從鏈接的搜索頁面獲取公司的行業信息。我使用Chrome的開發工具獲取xpath表單,但它會返回空括號。這裏似乎是什麼問題?lxml找不到Chrome提供的xpath?
from lxml import html
import requests
page = requests.get('https://www.linkedin.com/search/results/companies/?keywords=cisco.com')
tree = html.fromstring(page.content)
industry = tree.xpath('//*[@id="ember3734"]/div/div[1]/p[1]')
print(industry)
非常感謝!我可以使用任何驅動程序還是必須使用PhantomJS? – opamp
我認爲Phantomjs更好,但是是個人意見。你將會得到與Firefox或谷歌瀏覽器相同的結果。但我認爲phantomjs更輕。 – wu4m4n
@opamp您可以使用此https://gist.github.com/Wu4m4n/597367d32e443b9fe120f47d78d56bce安裝phantomjs – wu4m4n