Reborn in 2000, starting from the university website
Chapter 25 Website Redesign
Monday morning, a long lecture on "Data Structures".
On the podium, an elderly professor with gray hair was speaking into the microphone, lecturing on chains and binary trees in a way that sounded like a lullaby. The lecture hall was mostly empty except for a few high-achieving students in the front row, diligently writing away.
Bai Yuhang sat in the back row by the window, his pen flying across his notebook. He wasn't taking notes; he was just drawing three squares.
On the left is a box that says "Perpetual Calendar"; in the middle is a banner logo that says "Weather Forecast"; and in the bottom right corner is a small block that says "Stock Quotes".
He pushed the notebook aside, bumped into Zhang Jian, the third student who was secretly reading the "Computer Weekly" magazine by tucking it into his textbook, and kicked Wan Lianghao, the fourth student who was dozing off in the front row.
"Wake up, get to work."
Zhang Jian glanced at the notebook, his brows furrowing deeply: "Sixth Brother, what are you drawing? A perpetual calendar? Isn't the time displayed in the bottom right corner of the computer? This is just pointless!"
"Tell me now, what day of the lunar calendar is next Wednesday? Is that day auspicious for breaking ground or for weddings?"
Zhang Jian opened his mouth, then choked. He glanced again at the system time in the lower right corner; it was just plain Gregorian calendar numbers, cold and impersonal.
"These days, when netizens open their browsers, all they do is type in a URL and have no idea what else to do," Bai Yuhang said, pointing to the three boxes with his pen. "We need to give them something to do. This is called 'high-frequency, low-depth' demand. It doesn't need to be complicated, but it needs to make them want to look at it every day. One look, and the traffic will come."
Wan Lianghao rubbed his sleepy eyes, turned around, and lay down on the table, staring at the sketch: "That makes sense. But what about the weather and stocks? We can't exactly hire people to stand outside the weather bureau, can we? And stocks, that requires real-time data, which we don't have the qualifications for."
"Who told you to generate your own data?" Bai Yuhang lowered his voice, a wicked smile playing on his lips. "We'll be middlemen. The China Meteorological Administration's official website has data, and Sina Finance has real-time market data. We'll write a web crawler, scrape it, clean it up, and put it on our desktop and homepage."
"You're going to just steal it?" Wan Lianghao chuckled.
"That's what scholars do, called quoting." Bai Yuhang closed his notebook. This task looked simple, but it was full of pitfalls. In 2000, AJAX controls hadn't been developed yet. To make the user's page change data without clicking to refresh, you had to use iframe nesting and work with backend scripts for seamless refresh. This technology only works because of the slow internet speeds back then, so people wouldn't notice it.
As soon as the bell rang, the three of them didn't head towards the cafeteria at all.
At the school gate, Bai Yuhang carried three buckets of Master Kong braised beef noodles, Zhang Jian carried a bundle of ham sausages, and Wan Lianghao carried two large bottles of Coke, heading straight for the Daowai New Century Internet Cafe.
Zhao Jianjun was doing accounts at the bar when he saw this scene and was startled: "What's going on? You three little bosses, are you trying to cause trouble? Are you going to stage a protest here?"
"Brother Zhao, get a private room for us to retreat to." Bai Yuhang slapped fifty yuan on the bar counter. "Don't let anyone disturb us these next few days, except when we need to use the restroom. Oh, and make sure there's plenty of hot water."
Seeing this, Zhao Jianjun knew they were getting down to business. He tossed the fifty yuan back to Bai Yuhang and, without a word, led them into the internet cafe. He opened the door to the quietest private room at the back: "Those machines just had their graphics cards replaced, and the network cables and routers are new too. They've been individually adjusted. If anything's missing, just let me know."
As soon as the door to the private room closed, the steam from the instant noodles mingled with the aroma of ham sausage.
"Let's divide the work." Bai Yuhang opened his notebook. "Fourth brother, you're in charge of the front-end page. Embed these three modules into the homepage, and make sure the style is consistent with the current style. Don't make it look like a patch of weeds. Third brother, you're in charge of writing the scraping script. Extract the data from Sina Finance for me first. I'll be in charge of the core architecture and regular expressions."
"All done."
The three of them slurped down their noodles, and immediately the sound of keyboards clicking filled the air.
Initially, things went smoothly. For static data like the perpetual calendar, there are readily available algorithm libraries online that can be modified slightly to be used without needing to scrape it. The data source for the weather forecast was also relatively well-organized, and Wan Lianghao's front-end debugging was quite fast.
The problem lies with the stocks.
Three hours later, Zhang Jian pushed the keyboard, making such a loud noise that it almost overturned the empty instant noodle bucket.
"This is impossible to do!" Zhang Jian grabbed his hair, his face flushed. "What kind of garbage is this Sina Finance website? It's just tables nested within tables, forms nested within forms endlessly, the tags are a complete mess. I locate this 'td', and the next piece of data just goes into that 'div'. How am I supposed to track this? There's absolutely no pattern!"
He's a perfectionist and writes beautiful code, but when he encounters this kind of unreasonable "shit mountain" of code, he starts to lose his composure.
"Can't catch them all?" Bai Yuhang, with half a sausage dangling from his mouth, slid his chair over. "Let me see."
The screen was covered with dense HTML source code. Sina Finance's page did indeed use countless nested tables for layout purposes, which made it dizzying to look at.
"Are you counting which table it is?" Bai Yuhang glanced at Zhang Jian's code.
"How can you locate it without counting? It doesn't have an ID."
"Third brother, you're thinking like an honest person, like a student." Bai Yuhang swallowed the sausage, reached out and took the keyboard. "To deal with rogue code, you have to use rogue methods. Don't look at the structure, look at the features."
Bai Yuhang's fingers flew across the keyboard, opening a new script window.
"Look at this single stock price. No matter how many layers of tables it's nested in, it always has fixed characters before and after it. For example, the words 'latest price' are always followed by numbers and a decimal point."
A line of characters appeared on the screen: `preg_match('/latest price.*?(\d+\.\d{2})/',$content,$matches);`
"This is called a regular expression." Bai Yuhang pressed Enter to run the test.
The screen flashed, and a line of green numbers appeared: `18.56`. This was the latest stock price on the current page.
Zhang Jian was stunned, his eyes wide open, and he stared at the screen for a long time: "It's... out already? You don't need to know who its parent node is?"
"Who cares who the father is? I want the numbers, not to claim kinship." Bai Yuhang stood up and gave his seat back. "Sometimes, looking at things from a different perspective is much faster than sticking to the rules. The rest is up to you. Following this line of thinking, extract the opening price and the percentage change."
Zhang Jian sat in his chair, staring at the concise, even somewhat crude, line of code, motionless for a long time. After a while, he turned his head and saw Bai Yuhang explaining partial refresh of iframes to Wan Lianghao, muttering, "Sixth Brother, what the hell is going on in your head? This is way too damn wild."
"Stop talking nonsense and get to work." Bai Yuhang didn't even turn his head. "If we don't get this done before the market closes tonight, you wait, you won't get any sausages for dinner."
Once again, only the sound of keyboard typing filled the private room, but this time, the rhythm was noticeably faster.
You'll Also Like
-
The transmigrated villain wants to escape Feng Aotian's hellish situation.
Chapter 365 3 minute ago -
In music anime, band girls won't be alone.
Chapter 192 3 minute ago -
No kidding, even Rocks would have to offer me a cigarette.
Chapter 137 3 minute ago -
My anime-style card deck is fine!
Chapter 304 3 minute ago -
Practical teaching, all I want is your reward.
Chapter 251 3 minute ago -
I'm on the Ark, and I start out as Gretchen.
Chapter 272 3 minute ago -
If you're going on a blind date, do it properly, don't confiscate my property!
Chapter 43 3 minute ago -
Surviving in the chaos of battle, I'm grinding for proficiency.
Chapter 105 3 minute ago -
Reborn in 2000, starting from the university website
Chapter 118 3 minute ago -
Li Zhuiyuan, a corpse retriever, travels through a mysterious resurrection.
Chapter 83 3 minute ago