Reference link: How to print without line breaks in Python?
The installation of python common libraries under windows requires that the python development environment of annaconda is installed. As long as anaconda has been installed, installing other libraries is easy. Just use pip. If python is installed normally, it will bring its own pip installation tool, which can be viewed in the python scripts installation directory. Specific installation steps: Use Anaconda to manage the python development environment under windows The installation of python common libraries is the cornerstone of python crawler development.
These two libraries are the libraries that come with python. As long as python is installed correctly, you can directly call the two libraries. The verification in python mode is as follows
import urllib
import urllib.request
urllib.request.urlopen('http://www.baidu.com')
< http.client.HTTPResponse object at 0x0000024222C09240>
import re
Execute the command under pip3 install requests dos to install
Test whether the request library is installed correctly under python interaction
import requests
requests.get('http://www.baidu.com')
< Response [200]>
Mainly used to drive the browser, do tests and the like, js rendering and debugging
pip3 install selenium executes the installation, if you delete the library, directly pip3 uninstall selenium
Test whether it is installed correctly
import selenium
from selenium import webdriver
driver = webdriver.Chrome()
DevTools listening on ws://127.0.0.1:12052/devtools/browser/1f2faef9-0748-40f0-b955-9e41362ce55e
driver = webdriver.Chrome()
DevTools listening on ws://127.0.0.1:12722/devtools/browser/5ba65a50-df4a-47fd-b2d6-d313578d539d
driver.get('http://www.baidu.com') #The browser opened at this time will jump to the Baidu homepage.
driver.page_source #Can directly print the code of the current Baidu webpage
No interface browser, browser driver implementation under command line, complementary to selenium, the former will open the browser
Download the phantomjs installation package on the phantomjs official website, http://phantomjs.org/download.html
After placing it in the specified installation directory, configure environment variables, bin directory
Execute phantomjs directly under dos to see if the configuration is successful, as follows:
C:\Users\Robot_CHEN>phantomjs
phantomjs>
import selenium
from selenium import webdriver
driver = webdriver.PhantomJS() #Pay attention to the difference between webdrive.Chrom() in selenium
driver.get('http://www.baidu.com')
driver.page_source
xpath web page parsing library, realize web page parsing. pip3 install lxml can be installed directly
Under python interaction, use import lxml to confirm whether the installation is successful
Installation: pip3 install beatifulsoup4
Test installation:
from bs4 import BeautifulSoup #Use beautifulsoup to import from bs4 module
soup = BeautifulSoup('','lxml')
pip3 install pyquery performs the installation.
from pyquery import PyQuery as pq
doc = pq('')
doc = pq('Hello World')
result = doc('html').text()
result
' Hello World'
The driver library installation command for operating the mysql database: pip3 install pymysql. After the installation is complete, use the code python to operate the mysql database and execute CRUD.
import pymysql #import pymysql
db= pymysql.connect(host="localhost",user="root",
password="123456",db="mydatabase",port=3306)
cur = db.cursor()
#1. Query operation
sql = "select * from emp3"
try:
cur.execute(sql) #Execute sql statement
results = cur.fetchall() #Get all records of the query
print("id","name","password")
#Traversal results
for row in results :
id = row[0]
name = row[1]
password = row[2]
print(id,name,password)
except Exception as e:
raise e
finally:
db.close()
The installation is still pip install pymongo
import pymongo
client = pymongo.MongoClient('localhost')
db = client['mymongodb']
coll = db['mycoll']
mydict = { "name": "RUNOOB", "alexa": "10000" }
coll.insert_one(mydict)
print(coll)
''' The test results are as follows:
Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mymongodb'), 'mycoll')
'''
pip install redis can be installed
import redis
result = redis.Redis('localhost',6379)
result.set('name','jack')
print(result.get('name')) #b'jack'
You can view it in Flask's official website documentation, http://docs.jinkan.org/docs/flask/
Installation method pip install flask, test import flask in python interactive mode to see if an error is reported
12 Django installation, web server framework
The installation is very simple pip install django, test import import django
You can install jupyter with pip install jupyter. If you are using anaconda, jupyter is already installed by default. It is mainly used for online code writing and documentation, which is very powerful and convenient.
Unified statement: Regarding the original blog content, some of the content may be referenced from the Internet. If there is an original link, it will be quoted; if the original link is not found, please contact and delete it if there is any infringement. Regarding reposting the blog, if there is an original link, it will be declared; if the original link is not found, please contact to delete it if there is any infringement.
Recommended Posts