问题描述
我正在寻找Linux终端的命令,以便对内部服务器执行ping操作。
解决方法
使用GNU awk:
import requests
from bs4 import BeautifulSoup
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML,like Gecko) Version/13.1 Safari/605.1.15"}
res = requests.get('http://bj.xiaozhu.com/',headers=headers) #get method of appending the request header
soup = BeautifulSoup(res.text,'html.parser')
prices = soup.select('#page_list > ul > li > div.result_btm_con.lodgeunitname > span.result_price > I') #selector path of the prices
for price in prices:
print(price.get_text())
这将输出所有行,直到找到五次ping soren | awk '/ from /{if(c==5){exit}; c++} {print}'
。