Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does python capture the content of embarrassing encyclopedia?

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how python captures the content of embarrassing encyclopedia". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "python how to capture the content of embarrassing encyclopedia".

# capture the contents of the embarrassing encyclopedia import requestsfrom lxml import etreeclass Qiushi (): def _ _ init__ (self): self.url = 'http://www.qiushibaike.com/8hr/page/{}'; self.headers = {"User-Agent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1 Trident/5.0 "} Def parse_url (self, url): response = requests.get (url, timeout = 10, headers = self.headers) assert response.status_code = = 200print (url) return etree.HTML (response.text) def parse_content (self Html): item = html.xpath ('/ / div [@ class= "recommend-article"] / ul/li') print (item) for i in item: # content print (i.xpath ('. / div/a [@ class= "recmd-content"] / text ()') # funny number print ('. / div/div [@ class= "recmd-detail clearfix"] / div/span [1] / text ()') # comments number print ('. / div/div [@ class= "recmd-detail clearfix"] / div/span [4] / text ()) # user name print (i.xpath ('. / div/div [@ class= "recmd-detail clearfix"] / a/span/text ()') # avatar address print (i.xpath ('. / div/div [@ class= "recmd-) Detail clearfix "] / a _ def run (self): url = self.url.format (1) Html = self.parse_url (url); self.parse_content (html); if _ name__ = ='_ main__': qiu = Qiushi (); qiu.run () Thank you for your reading. The above is the content of "how python captures the content of embarrassing encyclopedia". After the study of this article, I believe you have a deeper understanding of how python captures the content of embarrassing encyclopedia, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report