python3中xpath爬51job

最近学python,练练手爬一些简单的网站页面,这里选取了51job页面python的岗位有多少,主要是为了练习xpath的使用。代码来了

import requests
from lxml import etree
def download(url):
    headers = {'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
    reponse = requests.get(url,headers = headers)
    reponse.encoding = "GBK"
    text = reponse.text
    html = etree.HTML(text)
    result =html.xpath('//*[@class=\'rt\']/text()')
    print(result[0].strip())


download("https://search.51job.com/list/180200%252C00,000000,0000,00,9,99,python,2,1.html?lang=c&stype=1&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=")
BaiduShurufa_2019-1-18_21-54-4.png

你可能感兴趣的:(python3中xpath爬51job)