【发布时间】:2020-04-01 18:58:08
【问题描述】:
伙计们,我想从 yahoo Finance 中获取公司所在的国家 - 美国,位于 Yahoo Finance 的个人资料页面中。链接是:
https://finance.yahoo.com/quote/AAPL/profile?p=AAPL
我尝试了这段代码,但无法提取它。我是抓取数据的新手,如果您能帮助我,我将不胜感激。
我的代码:
import requests
from lxml import html
xp = "//span[text()='Sector']/following-sibling::span[1]"
symbol = 'AAPL'
url = 'https://finance.yahoo.com/quote/' + symbol + '/profile?p=' + symbol
page = requests.get(url)
tree = html.fromstring(page.content)
d = {}
我更喜欢 lxm 和 requests 并且没有使用 beautifulsoup,所以更喜欢在代码库中指出。
不胜感激。
【问题讨论】:
标签: python web-scraping