Pennsylvania looked like a Republican dream.

After eight years of Democratic control, the state capital in Harrisburg was awash in indictments, and charges of bribery were common enough for many Pennsylvanians to consider their state government the most corrupt in the nation.

The incumbent governor, Milton J. Shapp, was barred by law from seeking a third term. Polls showed voters angry over the Harrisburg scandals as well as inflation and their taxes, making 1978 appear a good year for Republicans to ride a "throw-the-rascals-out" campaign into the statehouse.

But Peter F. Flaberty, the Democratic candidate for governor, appears to have spiked their guns.

On issue after issue, Flaherty got his licks in first and arranged the political battlefield so that Republican candidate Richard L. Thornburgh found many of his best shots sounding like me-too echoes.

Flaherty's campaign put early stress on his anticorruption and tax-cutting successes during his two terms as mavor of Pittsburgh.

Elliott Curson designed a successful series of television commercials that made Flaherty sound like a prince from a fairy tale - almost too good to be true.

"Once upon a time, there was a city on the verge of bankruptcy," one of them begins to a background of music-box tones. "Sounds like a fairy tale? It's not," the commercial says after describing Flaherty's record in improving Pittsburgh's financial condition, while he also reduced taxes.

Flaherty, 53, also beat Thornburgh, 45, to the punch on the Philadelphia issue that has so captured people's attention it has pushed the governor's race into the background - Mayor Frank Rizzo's attempt to change the city charter so that he can run for a third term.

Another Democratic candidate might have tried to play it safe by waffling on the charter change, but Flaherty moved even faster than Thornburgh to oppose Rizzo's effort.

Since three out of every four Philadephia voters are Democrats, Flaherty appears likely to receive a huge bonus from the heavy turnout that is expected because of interest over the charter-change issue.

Thornburgh's failure to capture the anticorruption, antitax and anti-inflation issues for himself and polls showing him 12 to 15 percentage points behind Flaherty heading into the last month of the campaign have brought a change in his tactics.

Instead of stressing his own qualifications and proposals, as he did earlier, Thornsburgh an assistant attorney general in the Ford administration, has turned his campaign into an all-out attack on Flaherty.

"One of my purposes now is to tie Flaherty to Shapp," he says. It hasn't worked so far because Flaherty anticipated the effort and sent Shapp a telegram the day before the Democratic primary asking the governor not to endorse him and not to speak out for him. "I wouldn't touch him with a 10-foot pole," Flaherty said when asked about Shapp the next day.

Thornburgh has printed leaflets headlined "The Real Pete Flaherty" with a front-page photograph of Flaherty and Shapp together and reminding voters that Flaherty endorsed Shapp when Shapp ran for governor.

In their first debate last week, Thornburgh repeatly accused Flaherty of being a longstanding member of the Shapp team who had a "deathbed repentance" this year. Flaherty waited until the end of the debate and then fired back. It was Richard M. Nixon, Flaherty said, who made Thornburgh a U.S. attorney.

Thornburgh also has gone on the attack against Flaherty's record as mayor of Pittsburgh. However, he is not yet showing these television spots in Pittsburgh only in areas where Flaherty is less well known.

He can't show them in Pittsburgh," Flaherty counters, "because people who think Thornburgh's a high-minded type would be disgusted."

The oddest part of the campaign is the candidates for lieutenant governor.

Flaherty's running mate is Robert P. Casey, a high school biology teacher and ice cream store owner who won the Democratic primary without campaigning because his name is identical to that of a respected former state auditor general. (Another Robert Casey is state treasurer thanks to the same confusion of names.)

"The man is an imposter. He's an insult to the voters of Pennsylvania," Thornburgh says of Casey.

On the other hand, Thornburgh rarely misses an opportunity to let the name of his running mate, William Scranton III, roll off his tongue, and all his campaign literature refers to Thornburgh/Scranton.

Like Casey, Scranton is making his first run for public office. He is the son of former governo Scranton, one of the most respected politicians in Pennsylvania.

"If it's the wrong Robert Casey, it's the wrong Bill Scranton, too," Flaherty says when his running mate is attacked.

Flaherty, who grew up poor on the streets of Pittsburgh and went to college on the GI bill, goes on to say that Casey always worked for a living, while Scranton had the opportunity to travel widely and take up Transcendental Meditation in India.

Flaherty, however, doesn't treat Casey as though he were an asset. He has ordered Casey to remain at his teaching job and do little campaigning, while Scranton is campaigning every day.

Thornburgh's hopes of overcoming Flaherty's lead are based on money. Thornburgh spent more to win the Republican primary than Flaherty plans to spend in the general election - $1 million dollars to $800,000. He refuses to name a spending target for his general election campaign, but it may total $2.5 million, much of it TV advertising during the final weeks.

"We'll raise every penny we can and spend every cent we raise," Thornburgh says. A large part of his funding has come from prominent Pittsburg families, including $200,000 in gifts and loans during the primary from the Heinz family.

Money, Thornburgh says, is the only weapon he has with which to overcome Flaherty's greater name recognition as a result of Flaherty's years in politics and the fact that registered Democrats outnumber Republicans in Pennsylvania by 842,000.

In his first run for office, Thornburgh portrays himself as a political outsider. "I think Pennsylvania is sick and tired of slick politicians," he says.

Flaherty tells his audiences that "you're going to hear all kinds of nasty things about me in the next few weeks" in Thornburgh's media advertising.

"The question," Flaherty says, "is whether Thornburgh is credible enough to cut me down. I have a record. He does't."