coinmarketcap.com爬虫
写的真是蛋疼
# -*- coding:utf-8 -*- import requests from lxml import etree headers = { 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' } def get_tag(): html = requests.get("https://coinmarketcap.com/zh/rankings/exchanges/",headers=headers).text keys = etree.HTML(html) keyss = keys.xpath("//td[@class='no-wrap currency-name']/@data-sort") for i in keyss: url = "https://coinmarketcap.com/zh/exchanges/"+i get_url(url) def get_url(url): html = requests.get(url, headers=headers).text keys = etree.HTML(html) keyss = keys.xpath("//div[@class='col-xs-12']/ul[@class='list-unstyled']/li/a/@href") for i in keyss: print i break if __name__ == '__main__': get_tag()