M. Silverberg/TRAFFIC Southeast Asia, via Associated Press

HONG KONG — Walk into a barn lined with cramped bear cages and you hear two kinds of sounds from the animals — either a high-pitched whimper or a deep, raging snarl.

It’s a distasteful experience, and saddening, watching a keeper stab anesthesia into a thrashing bear, then locate the groggy animal’s gall bladder with a small sonogram machine and withdraw a fat hypodermic’s worth of bile. It’s not for the squeamish.

The practice is gruesome enough that hundreds of thousands of Chinese have attacked the pharmaceutical company Guizhentang with online complaints over the firm’s plans to triple the size of its bear-bile farms through a public offering of shares on the Shenzhen stock exchange. The company said it currently farms about 400 bears.

The company also said its Web site was hacked last Saturday, one hour after it posted an invitation for the public to visit its bear farm.

Outrage does seem to be growing in China. The former N.B.A. star Yao Ming recently visited and endorsed a sanctuary run by the Animals Asia Foundation near Chengdu, in Sichuan Province. The group estimates that about 20,000 black bears are kept on about 100 bile farms in China.

The Ta Foundation, a private animal welfare group, recently submitted a petition to the Chinese regulatory authorities signed by 72 public figures, including Ding Junhui, a famous Chinese snooker player, Chen Danqing, a well-known painter, and Cui Yongyuan, a TV host.

The comedian Ricky Gervais also has been a longtime supporter of campaigns to stop bile farms. Earlier this month a rescue bear he sponsored died.

Woke up to the news that my beautiful rescue bear Stan has died. At least he experienced 2 years of freedom and love twitter.com/rickygervais/s… — Ricky Gervais (@rickygervais) February 3, 2012

Bear bile is prized in traditional Chinese medicine for its alleged ability to relieve muscle aches, joint pains, fever, migraines and hangovers, as well as being a curative for impotence, gallstones, cirrhosis, even cancer. Synthetic compounds are just as effective for many of these ailments, but many Asians, especially Chinese and Vietnamese men of a certain age, favor fresh bile. Drops of newly extracted bile or flakes of bile powder are typically added to rice wine.

I saw the bile-milking at a bear farming operation outside Hanoi. A dozen or so Vietnamese buyers were there, too — intent on watching the process to ensure their bile would be as fresh as possible. The whole thing was illegal, but hardly secret.

The farm office was a windowless concrete room with a couple of battered couches and an old TV. On a sideboard, a dozen large glass jugs of rice wine were on display — with amputated bear paws marinating inside. Resting at the bottom of one container, barely visible in the cloudy sediment, was a tiny bear fetus.

Asiatic black bears — they’re also known as moon bears for the crescent of white on their chests — can grow to 400 pounds or more, but the cages at the Hanoi farm were just 4 feet by 5 feet, and most were not high enough for the bears to stand up.

The head of the Chinese Association of Traditional Chinese Medicine, Fang Shuting, said last week that “bile extraction doesn’t harm bears.”

Wildlife biologists vehemently disagree, saying the needle sticks, catheterization and repeated draining of the gall bladder creates infections and leakage, which can lead to peritonitis and septicemia. “An excruciating death,’’ said one scientist.

“The process of extracting bear bile is like turning on a tap: natural, easy and without pain,’’ Mr. Fang insisted. “After they’re done, the bears can even play happily outside. I don’t think there’s anything out of the ordinary! It might even be a very comfortable process!”

A commenter on the popular Chinese microblogging site Sina Weibo said: “I don’t believe it at all that extracting bile is as easy and comfortable as Fang said. Why doesn’t he extract the bile from his body in the same way to prove it?”

A video of a bile extraction — on Shanghaiist, via the Chinese sharing site Youku — is here.

The bear milking I saw outside Hanoi in 2002 was horrifying.

The owner of the Vietnamese operation, Nguyen Hong Ha, told me he was expanding his operation. He had just ordered 10 new bears to be smuggled in from Laos at a cost of $6,000 each. Asked how he circumvented anti-trafficking regulations, he smiled and said, “I have a brother in the Forestry Department.” The department was supposedly in charge of catching animal traders and policing the bear farms.

With a dozen local buyers looking on, Mr. Ha’s workers tranquilized a highly agitated 5-year-old female bear. They then rolled her onto her back and bound her, spread-eagled, with ropes and cords. Using a toaster-size ultrasound machine, they located the gall bladder, stuck in a 7-inch syringe and slowly withdrew about a quarter-pint of bile. The whole procedure took 15 minutes.

Mr. Ha’s take for the morning from the one female was $800 — more than twice the average annual salary in Vietnam at the time. If he milks his 45 bears five times a year, Ha said he would gross $180,000, a fortune in Vietnam.

And even if the milking procedures reduced a bear’s life expectancy from 24 years to seven or eight, Mr. Ha figured he could add to his profit by hacking off the occasional paw to sell to a restaurant.

In one section of his farm, five of the 14 caged bears had paws missing. One bear, a big male, was missing two.