In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about how to get titles and links in python, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Put the code first.
From requests_html import HTMLSessionsession = HTMLSession () url = "https://my.oschina.net/u/4798232"r = session.get (url) for i in range (1,12): I = str (I) urlxpath ='/ / * [@ id=" newestBlogList "] / div [1] / div ['+ iTunes'] / div/a' bt = r.html.xpath (urlxpath, first=True). Text c = urlxpath+'/@href' link = r.html.xpath (c) First=True) a = "original" if bt.find (a) =-1:print (bt) print (link) else:print (bt.replace (a, ")) print (link)
First of all, this is operated through xpath. You can see my https://zjzdmc.top/jsfx/47.html article on how to copy xpath. There are motion pictures in it.
Then importing libraries and other things is a clich é. In the a tag, the xpath you copy is / / * [@ id= "newestBlogList"] / div [1] / div ['+ iTunes'] / div/a, and then, if we get the title and add the attribute of .text, it will become text, and we can look at the text in F12 and find that there is only the title, and we need to connect. Just add this / @ href to get the link. But at present, there is no better way to get all the text sequences, so let's just look at the id of the previous article and the id of the last article, and record it. After that, we only need to traverse the values of 1-12, and then add variables to the string as string + variable + string'/ / * [@ id= "newestBlogList"] / div [1] / div ['+ iTunes'] / div/a' as shown in the text to get the titles of all articles, and then add / @ href to the previously defined variable urlxpath to get the link in the changed xpath. Then the output will be ready.
The above is how to get the title and link in python. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.