1. url:https://www.landchina.com/default.aspx?tabid=226python
2. target: 瀏覽器
3. 簡單分析cookie
3.1 打開fiddler和chorme無痕瀏覽器,訪問目標網站,看看都加載了哪些請求。session
能夠看到,一共請求了3次,纔得到最終咱們想要的數據。學習
3.2 請求1:網站
url就是網站url,響應是一堆js。將js扣出來執行一下,發現是這麼一個東西:url
咱們再看看第二個請求的url:spa
這不就是第二個請求的url嘛。3d
3.2 請求2,請求3的cookie是同樣的。因此咱們用requests庫中的session來訪問第一步生成的url和目標url。完整代碼以下:code
python:
import requests from afterWork.config import proxies, userAgent import execjs import re targetUrl = 'http://www.landchina.com/default.aspx?tabid=226' sess = requests.session() res = sess.get(targetUrl) with open('jsCode.js', 'r') as f: jsCode = f.read() ctx = execjs.compile(jsCode) location = ctx.call('YunSuoAutoJump') # print(location) second_url = "http://www.landchina.com" + location _ = sess.get(second_url) res = sess.get(targetUrl) # print(res.text) regForInfo = r'<td class="gridTdNumber">(.*?)<td class="gridTdNumber">' infoList = re.findall(regForInfo, res.text) # print(infoList) for info in infoList: print(info)
初步提取結果:
只有單序號沒有雙序號,下了一跳,還覺得反爬這麼嚴,單雙號分開反爬。看了眼網頁源碼才知道沒問題。匹配下就出來了。
學習研究,勿做他用。js代碼很簡單,沒有拿過來。