requests
pip3 install requests
selenium
pip3 install selenium
安装好后,测试一下:
from selenium importwebdriver
driver= webdriver.Chrome()
执行后报错了:
需要安装chromedriver才能完成chrome浏览器的驱动。
可以从这里下载适合自己的chromedriver(需要对应自己的chrome版本!!!):https://npm.taobao.org/mirrors/chromedriver
比如我的是windows,解压后将chromedriver.exe放到某个配置好环境变量的目录下。
运行:
from selenium importwebdriver
driver=webdriver.Chrome()
driver.get("https://www.baidu.com")print(driver.page_source)
可以看到,自动打开百度并获取到了源代码。
但是,在做爬虫的时候,一直打开浏览器是不方便的,这时就需要一个没有界面的"浏览器"----phantomjs。
解压后,将bin目录配置到环境变量中。
from selenium importwebdriver
driver= webdriver.PhantomJS(executable_path=r"D:\phantomjs-2.1.1-windows\bin\phantomjs.exe")
driver.get("https://www.baidu.com")print(driver.page_source)
lxml
pip3 install lxml
beautifulsoup
pip3 install beautifulsoup4
from bs4 importBeautifulSoup
soup= BeautifulSoup("", "lxml")
pyquery
pip3 install pyquery
from pyquery importPyQuery as pq
doc= pq("hello!")
result= doc("html").text()print(result) #hello!
pymongo
pip3 install pymongo
importpymongo
client= pymongo.MongoClient("localhost")
db= client["test_db"]
db["table"].insert({"name": "pd"})
result= db["table"].find_one({"name": "pd"})print(result)
jupyter
pip3 install jupyter
相当于一个记事本,它是运行在网页端的。
在cmd中输入:jupyter notebook,就会自动打开浏览器。点击new python3,即可在网页上运行代码。