In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to use requests to obtain web pages in Python. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
1. Use pycharm to create a new project. Check "Inherit global site-packages" when creating a new project, otherwise the requests class library may not be found.
2. Write the code, and we see that the amount of data on the web page is 101 lines, as follows:
The code is as follows:
Project structure (not important):
Program code:
First of all, we have to analyze the source code of the web page, press F12 in the browser to view the source code, copy all the source code to a new pycharm HTML document, you can see the corresponding tree structure.
We can see that in the edit box on the left, everything with a "-" sign is in the tree structure. From this we can know that if you want to get the td, the complete tree structure is:
Html-body-div-table-tr-td
But the tr is multiple, and the first one is the header, so the first one is not what we want, so we have to discard the first header.
In addition, there are multiple td, and we only need the second td in each tr, so we can get it by subscript.
The final complete tree structure is: / html/body/div/table/tr [postion () > 1] / td [2]
So, the code is as follows:
Finally, run the result:
After reading the above, do you have any further understanding of how to use requests to get web pages in Python? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.