实习僧的网页解析很简单,重点在于字体的加密破解。它的字体加密是使用自定义字体的。然后需要找到对应字体,然后通过编码为utf-8的形式来获取每个数字和相应字节的对应关系,使用这个对应关系来对相应的编码进行替换就行了。具体看代码。
import requests
from bs4 import BeautifulSoup
headers = {
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
}
def main():
for page in range(1,5):
response = requests.get('https://www.shixiseng.com/interns?page={}&keyword=python'.format(page),
headers = headers)
# print(response.text)
soup = BeautifulSoup(response.text,'lxml')
offers = soup.select('.intern-wrap.intern-item') #空格使用.代替
print(offers)
for offer in offers:
url = offer.select('.f-l.intern-detail__job a')[0]['href']
print(url)
detail_url(url)
def detail_url(url):
html = requests.get(url,headers=headers)
soup = BeautifulSoup(html.text,'lxml')
title = soup.title.text
company_name = soup.select('.com_intro .com-name')[0].text
# 解决加密字体
# 先获取字体
salary = soup.select('.job_money.cutom_font')[0].text.encode('utf-8')
# 150-200/天
# '\xef\xa3\x8c\xee\xbd\xac\xee\x96\xb6-\xee\xbe\xaf\xee\x96\xb6\xee\x96\xb6/\xe5\xa4\xa9'
# 1 是由\xef\xa3\x8c所代表的
# 5 是由\xee\xbd\xac所代表的
# 0 是由\xee\x96\xb6所代表的
salary = salary.replace(b'\xef\xa3\x8c',b'1')
salary = salary.replace(b'\xee\xbd\xac',b'5')
salary = salary.replace(b'\xee\x96\xb6', b'0')
salary = salary.replace(b'\xee\xbe\xaf', b'2')
salary = salary.replace(b'\xef\x9e\x80',b'3')
salary = salary.replace(b'\xee\x93\x81',b'4')
salary = salary.replace(b'\xef\xa0\x9d',b'8')
salary = salary.replace(b'\xef\x90\xad',b'7')
salary = salary.replace(b'\xee\x85\xa7',b'9')
salary = salary.decode().strip()
# 对于每隔几小时就换的字体。需要即时爬取。
# salary = salary.replace(b'\xe5\xa4\xa9',b'天') 替换中文报错
# print(salary)
print(title,company_name,salary)
if __name__ == '__main__':
main()
下面是分析字体的代码
print('-/天'.encode('utf-8'))
# 150-200/天
# '\xef\xa3\x8c\xee\xbd\xac\xee\x96\xb6-\xee\xbe\xaf\xee\x96\xb6\xee\x96\xb6/\xe5\xa4\xa9'
# 1 是由\xef\xa3\x8c所代表的
# 5 是由\xee\xbd\xac所代表的
# 0 是由\xee\x96\xb6所代表的
# 其余同理
# 天 \xe5\xa4\xa9
注意在字体更换之前即时爬取。