- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 python 中编写了一个小脚本,使用 xpath 从 yahoo finance 中抓取显示在左侧区域的标题。该页面中有几个标题,但是当我运行我的脚本时,我只得到三个标题。我不想在这种情况下使用 Selenium ,因为我至少得到了最低限度的结果。我试图在我的脚本中使用“时间”来让网页完全加载。然而,似乎与“时间”无关。除了使用 selenium 之外,我如何从该网页获取所有标题?这是我尝试过的:
import time
import requests
from lxml import html
response = requests.get("https://finance.yahoo.com/").text
time.sleep(5)
root = html.fromstring(response)
for title in root.xpath("//a[u[@class='StretchedBox']]/text()"):
print(title)
最佳答案
我试用了您的代码,显然我获得的不仅仅是 3 个标题。
Yahoo 可能只是更改了他们网站的动态设置,使您的代码能够解析更多标题。
输出:
This could get 'very ugly, very fast' for Boeing, says one market expert
Toys R Us submits plan to liquidate its US business, will close or sell all US stores
Sears Gains After Tax Benefit Helps Retailer Swing to a Profit
Blood, Fraud and Money Led to Theranos CEO's Fall From Grace
Why Cisco Systems Is Looking Like a Must-Own Stock
Realty Income (O) Announces Hike in Monthly Dividend Payment
Tillerson's exit has 'very big implications' for oil prices: RBC’s Helima Croft
Kevin O'Leary shares his No. 1 trick for tipping at a res...
For J C Penney Co. Inc. Stock Survival is the Victory
Why Ford (F) Stock Popped Despite Recalling 1.4 Million Vehicles
Toys 'R' Us Liquidation Reveals a Dangerous Trend Forming in U.S. Retailing
Theranos CEO Elizabeth Holmes settles with SEC, agrees to...
Manafort Urges Judge to Dismiss Laundering and Lobbying Case
‘Dow Theory’ Warning Signal Spells Trouble for These 5 Stocks
General Electric Company Stock Is Ugly, But It Has Potential for the Gambler
This popular Dow stock looks ready to join GE on the discard pile
Intel's Broadcom Buyout Rumors Put These 3 Stocks at Risk
The SEC isn't sending Theranos CEO Elizabeth Holmes to jail for fraud — here are her punishments
Former Equifax CIO Charged With Insider Trading in Data Breach
Lyft is teaming up with automotive industry giant Magna to develop self-driving cars — and getting a $200 million investment (MGA, GM, GOOGL)
Google, Apple face EU law on business practices
Disney Elevates Two Top Executives in Possible CEO Bake-Off
Nokia Oyj Stock Could Break out over the Next Two Years
Wall Street gains as White House plays down trade war chances
U.S. retail sales falter; inflation creeping higher
关于python - Scraper 收集了很少的标题并忽略了其余的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45446741/
我有 python 应用程序,它需要每天执行大约 20 000 次专有应用程序(不时崩溃)。 问题是当应用程序崩溃时,Windows 会自动触发 WerFault这将使程序挂起,因此 python's
我弄清楚这里的问题是什么。很少(50 个数据中有 3 个)插入到数据库中的数据不完整,如下所示: 用于插入的 PHP 代码是正确的。数据库中没有值的所有值都来自 SELECT 标记 HTML(year
我有一个包含对象的列表,其中包含以下字段:完整、不完整、继续。我想根据这三个部分对我的列表进行排序。首先,我想添加 header: INCOMPLETE 和所有元素(如果此字段为真)。之后我想添加标题
我们有一个名为模型的包 在模型中,我们有一个 TopicM 模块,它定义了一个类 Topic我们将它导入同一个包中名为 GeneralM 的模块中。有时(很少)我们会收到此错误: 可能是什么原因?会不
通过简单地将 TextViews 文本设置为在代码中定义的字符串(永远不能是 null)我有时会得到一个 ArrayIndexOutOfBoundsException,这只发生在我的实时应用程序中,我
我在 NodeJS 中运行一个 restify 服务器。在极少数情况下,大约 0.05% 的 HTTPS 请求会导致 net.js 报告以下错误: Error: accept EPERM at
我不明白,为什么Eclipse更新变得如此不可靠?大约每次使用它时,我都会遇到一些问题! 例如,现在我遇到下面一堆谵妄。禁用“联系所有软件站点”没有帮助。 An error occurred whil
为了呈现一堆节点,每帧一个,直到它们都出现在屏幕上,我想在 update() 调用中做这样的事情。 警告,伪代码接近: update(){ switch presentNodes_inOrderOfA
此 NSPersistentStoreCoordinator 没有持久存储。它无法执行保存操作。 NSInternalInconsistencyException(SIGABRT) This NSPe
我是一名优秀的程序员,十分优秀!