NEW YORK (Reuters) - U.S. stocks advanced on Friday as upbeat earnings helped investors shrug off heightened trade anxieties and weaker-than-expected July jobs growth.

For the week, the S&P 500 and the Nasdaq gained ground, up 0.8 percent and 1.0 percent, respectively, while the Dow was essentially flat. The S&P 500 notched its fifth straight weekly gain, its longest such streak of the year.

The second-quarter reporting season nears its final stretch with 406 of the companies in the S&P 500 having reported, 78.6 percent of which came in above Street estimates, according to Thomson Reuters data.

China launched its latest salvo in the ongoing trade spat, unveiling new tariffs on 5,207 goods imported from the United States, including liquefied natural gas (LNG) and some aircraft.

Earlier this week, Chinese officials promised retribution after the Trump administration proposed hiking tariffs to 25 percent on $200 billion worth of goods imported from China.

A report from the Labor Department showed the U.S. economy added 157,000 jobs in July, fewer than the 190,000 economists expected, though the unemployment rate edged down to 3.9 percent.

Other data showed the U.S. trade deficit surged 7.3 percent in June to $46.3 billion, its biggest increase since November 2016. The politically sensitive trade gap with China widened by 0.9 percent to $33.5 billion.

“We have the trade numbers and we have the continuation of the ongoing trade war with China, which is not a good thing, obviously,” said Michael Geraghty, equity strategist at Cornerstone Capital Group.

“Some of the benefits of the tax cut will be wearing off, in addition we have this trade skirmish, so in my opinion investors will be quite skittish in the second half of the year,” Geraghty added.

Traders work on the floor of the New York Stock Exchange shortly after the opening bell in New York, U.S., July 31, 2018. REUTERS/Lucas Jackson

Shares of Apple Inc AAPL.O rose modestly a day after becoming the first publicly-traded U.S. company to reach $1 trillion in market value.

The S&P consumer staples sector .SPLRCS rose 1.2 percent. Its advance was led by Kraft Heinz KHC.O, up 8.6 percent after the packaged foods company topped quarterly profit and revenue estimates.

The Dow Jones Industrial Average .DJI rose 136.42 points, or 0.54 percent, to 25,462.58, the S&P 500 .SPX gained 13.13 points, or 0.46 percent, to 2,840.35 and the Nasdaq Composite .IXIC added 9.33 points, or 0.12 percent, to 7,812.02.

Of the 11 major sectors of the S&P 500, energy .SPNY was the sole percentage loser. Oil prices CLc1 gave up gains from the previous session, weighed upon by concerns about trade and demand for crude, while hedge funds and other money managers cut their bullish crude bets this week.

Shares of Dish Network Corp DISH.O jumped 14.5 percent following its better-than-expected quarterly earnings report.

Executives for American International Group Inc AIG.N tried to downplay weak earnings and promised a turnaround, but the insurer's shares dipped 2.7 percent.

Cyber security firm Symantec Corp SYMC.O was among the biggest percentage losers on the S&P, dropping 7.8 percent after announcing a workforce reduction and lowering its yearly revenue forecast.

Advancing issues outnumbered declining ones on the NYSE by a 1.51-to-1 ratio; on Nasdaq, a 1.41-to-1 ratio favored decliners.

The S&P 500 posted 22 new 52-week highs and two new lows; the Nasdaq Composite recorded 73 new highs and 70 new lows.

Volume on U.S. exchanges was 5.96 billion shares, compared with the 6.29 billion-share average over the last 20 trading days.