视频地址 https://www.bilibili.com/video/av31369828?t=39&p=7
主要代码如下
#encoding:utf-8
#随便找一个就可以,因为现在这个67就是我搜索的python,但是格式真的没变
import selenium #测试框架
import selennium.webdriver #模拟浏览器
import re
mystr = """<div class = "rt">
共67条职位
<\div>"""
def getnumberbyname(searchname): #可能这里有一些混乱,手头没有python环境就没测试,大致就先这样吧
url="https://search.51job.com/list/240200,000000,0000,00,9,99,"+searchname +",2,1.htmllang=c&stype=&postchannel=0000&workyear=99&cotype=99°efrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&adius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&lin=&specialarea=00&from=&welfare=
driver = selenium.webdriver.Firefox() #调用火狐浏览器
driver.get(url) #访问链接
pagesource = driver.page_source #抓取网页源代码
restr = """(\\d+)""" #先抓大,再抓小;尤其是空白字 符出现的时候
regex = re.compile(restr, re.IGNORECASE)
mylist = regex.findall(pagesource)
newstr = mylist[0].strip()
driver.close()#关闭
return mylist[0]
pythonlist = ["python", "python 运维", "python 测试", "python 数据", "python web"]
for oystr in pythonlist:
print pystr, getnumberbyname(pystr)