本人開發環境: python 3.7.1 和pychar
準備 首先 安裝requests: pip install requests
安裝lxml :pip install lxml
安裝 beautifulsoup :pip install beautifulsoup4
安裝成功後 編寫如下**:
(如果對 pip 不熟悉 可以看下這個文章 了解模仿使用
import requestsimport time
import random
from bs4 import beautifulsoup
context=requests.get('')
# print(context.text)
baetu=beautifulsoup(context.text,'lxml')
# lis=list
lis=baetu.select('.grid_view li')
for li in lis:
time.sleep(random.random()+1)
span_list=li.select('.star span')
print("-"*50)
com_num=span_list[3].text.replace('人評價','')
print(int(com_num))
(爬蟲的本質是解析 網路語言 html ,從中提取有用資訊)
如果對web開發有一定了解 上面**非常簡單,否則簡易先去簡單了解下 web端 頁面的html
上面同樣的道理可以獲取很多你需要的其他資訊。
python 微信爬蟲 python 微信爬蟲例項
import urllib.request import urllib.parse import urllib.error import re,time import queue import threading operner urllib.request.build opener operner...
python爬蟲 12306獲取列車座位資訊
主要核心 get citycode.py import requests def get city target req requests.get url target station names req.text station names new station names.replace va...
python微信爬蟲
import urllib.request import re import time import urllib.error 自定義函式,功能為使用 伺服器爬乙個 def use proxy proxy addr,url 異常處理機制 try req urllib.request.request ...