In view of the fact that I used python to write a crawler before and helped operators crawl JD.com’s product brands and categories, this time I also used python to do a simple crawling of a single page version, and will add more later.
#-*- coding: UTF-8 -*- import requests import sys from bs4 import BeautifulSoup #------知乎答案收集---------- #获取网页body里的内容 def get_content(url , data = None): header={ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, sdch', 'Accept-Language': 'zh-CN,zh;q=0.8', 'Connection': 'keep-alive', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.235' } req = requests.get(url, headers=header) req.encoding = 'utf-8' bs = BeautifulSoup(req.text, "html.parser") # 创建BeautifulSoup对象 body = bs.body # 获取body部分 return body #获取问题标题 def get_title(html_text): data = html_text.find('span', {'class': 'zm-editable-content'}) return data.string.encode('utf-8') #获取问题内容 def get_question_content(html_text): data = html_text.find('div', {'class': 'zm-editable-content'}) if data.string is None: out = ''; for datastring in data.strings: out = out + datastring.encode('utf-8') print '内容:\n' + out else: print '内容:\n' + data.string.encode('utf-8') #获取点赞数 def get_answer_agree(body): agree = body.find('span',{'class': 'count'}) print '点赞数:' + agree.string.encode('utf-8') + '\n' #获取答案 def get_response(html_text): response = html_text.find_all('div', {'class': 'zh-summary summary clearfix'}) for index in range(len(response)): #获取标签 answerhref = response[index].find('a', {'class': 'toggle-expand'}) if not(answerhref['href'].startswith('javascript')): url = 'http://www.zhihu.com/' + answerhref['href'] print url body = get_content(url) get_answer_agree(body) answer = body.find('div', {'class': 'zm-editable-content clearfix'}) if answer.string is None: out = ''; for datastring in answer.strings: out = out + '\n' + datastring.encode('utf-8') print out else: print answer.string.encode('utf-8') html_text = get_content('https://www.zhihu.com/question/43879769') title = get_title(html_text) print "标题:\n" + title + '\n' questiondata = get_question_content(html_text) print '\n' data = get_response(html_text)
Output result:

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
