import requests
from scrapy import Selector
url = 'http://www.porters.vip/confusion/food.html'
response = requests.get(url)
html = Selector(text=response.text)
mappings = {'vhk08k': '0', 'vhk6zl': '1', 'vhk9or': '2', 'vhkfln': '3', 'vhkbvu': '4',
'vhk84t': '5', 'vhkvxd': '6', 'vhkqsc': '7', 'vhkjj4': '8', 'vhk0f1': '9'
}
class_values = html.xpath('//div[@class="col more"]/d/@class').extract()
number = ''
for k in class_values:
number += mappings.get(k, '-')
print(number)
参考反爬虫原理与实战