python爬虫常用的模块分析
本文对Python爬虫常用的模块做了较为深入的分析,并以实例加以深入说明。分享给大家供大家参考之用。具体分析如下:
creepy模块
某台湾大神开发的,功能简单,能够自动抓取某个网站的所有内容,当然你也可以设定哪些url需要抓。
地址:https://pypi.python.org/pypi/creepy
功能接口:
set_content_type_filter:
设定抓取的content-type(header中的contenttype)。包括text/html
add_url_filter:
过滤url,传入的可以是正则表达式
set_follow_mode:
设定递归模式,F_ANY:该页面上所有链接都会抓取。 F_SAME_DOMAIN和F_SAME_HOST类似。即同一个域名的都会抓取。F_SAME_PATH:同一路径的抓取。例如bag.vancl.com/l1/d3/1.jpg path为l1/d3/1.jpg,则path为l1/d3/*的都会抓取。这里可以根据需要增加自己的递归模式
set_concurrency_level:
设定线程最大数
process_document:
一般需要重写,处理网页内容,提取自己需要的内容。
selenium
可视化界面,抓取自动化,api使用超简单,完全像是自己在操作浏览器。
官方网站:http://www.seleniumhq.org/
python官方网站
http://pypi.python.org/pypi/selenium
webdriver api(很好用,建议多了解一下)
http://www.seleniumhq.org/docs/03_webdriver.jsp
以下是一个抓取凡客网站的例子:
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time browser = webdriver.Firefox() browser.get('http://bag.vancl.com/28145-28167-a18568_18571-b1-n3-s1.html#ref=hp-hp-hot-8_1_1-v:n') elem = browser.find_element_by_name('ch_bag-3-page-next') # Find the search box time.sleep(1) print elem.get_attribute("href") elem.click() time.sleep(1) elem = browser.find_element_by_name('ch_bag-3-page-next') # Find the search box print elem.get_attribute("href") elem.click()
希望本文所述对大家的Python程序设计有所帮助。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to download DeepSeek Xiaomi? Search for "DeepSeek" in the Xiaomi App Store. If it is not found, continue to step 2. Identify your needs (search files, data analysis), and find the corresponding tools (such as file managers, data analysis software) that include DeepSeek functions.

The key to using DeepSeek effectively is to ask questions clearly: express the questions directly and specifically. Provide specific details and background information. For complex inquiries, multiple angles and refute opinions are included. Focus on specific aspects, such as performance bottlenecks in code. Keep a critical thinking about the answers you get and make judgments based on your expertise.

Just use the search function that comes with DeepSeek. Its powerful semantic analysis algorithm can accurately understand the search intention and provide relevant information. However, for searches that are unpopular, latest information or problems that need to be considered, it is necessary to adjust keywords or use more specific descriptions, combine them with other real-time information sources, and understand that DeepSeek is just a tool that requires active, clear and refined search strategies.

DeepSeek is not a programming language, but a deep search concept. Implementing DeepSeek requires selection based on existing languages. For different application scenarios, it is necessary to choose the appropriate language and algorithms, and combine machine learning technology. Code quality, maintainability, and testing are crucial. Only by choosing the right programming language, algorithms and tools according to your needs and writing high-quality code can DeepSeek be successfully implemented.

Detailed explanation of DeepSeekAPI access and call: Quick Start Guide This article will guide you in detail how to access and call DeepSeekAPI, helping you easily use powerful AI models. Step 1: Get the API key to access the DeepSeek official website and click on the "Open Platform" in the upper right corner. You will get a certain number of free tokens (used to measure API usage). In the menu on the left, click "APIKeys" and then click "Create APIkey". Name your APIkey (for example, "test") and copy the generated key right away. Be sure to save this key properly, as it will only be displayed once

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

This article explores the quantitative trading functions of the three major exchanges, Binance, OKX and Gate.io, aiming to help quantitative traders choose the right platform. The article first introduces the concepts, advantages and challenges of quantitative trading, and explains the functions that excellent quantitative trading software should have, such as API support, data sources, backtesting tools and risk control functions. Subsequently, the quantitative trading functions of the three exchanges were compared and analyzed in detail, pointing out their advantages and disadvantages respectively, and finally giving platform selection suggestions for quantitative traders of different levels of experience, and emphasizing the importance of risk assessment and strategic backtesting. Whether you are a novice or an experienced quantitative trader, this article will provide you with valuable reference

DeepSeekR1 model local deployment guide: Unlocking data analysis and prediction potential DeepSeek is a powerful data analysis and prediction tool, and its R1 model can provide efficient and accurate model support for various application scenarios. This guide will provide you with detailed instructions on how to deploy the DeepSeekR1 model in your on-premises environment to help you get started quickly and take advantage of its power. System requirements for the local deployment step preparation stage of the DeepSeekR1 model: Please make sure that your local machine meets the minimum system configuration requirements of DeepSeek (for specific requirements, please refer to the official DeepSeek document). Software installation: Download and install the installation package provided by DeepSeek and follow the installation guide
