level 1
残垣旧梦_
楼主
def main():
kw = parse.quote(parse.quote(input("请输入要搜索的岗位信息:")))
baseurl = "https://search.51job.com/list/000000,000000,0000,00,9,99," + kw
# url = baseurl + ",2,1.html"
# html = askUrl(url)
# print(html)
getData(baseurl)
# 制作URL网页
def askUrl(url):
head = {
"User-Agent": "Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko)Chrome / 97.0.4692.71Safari / 537.36"
}
request = urllib.request.Request(url, headers=head)
html = " "
try:
reponse = urllib.request.urlopen(request)
html = reponse.read()
except urllib.error.URLError as e:
if hasattr(e, "code"):
print(e.code)
if hasattr(e, "reason"):
print(e.reason)
return html
# 爬取网页--网页解析
def getData(baseurl):
datalist = []
for i in range(1, 10):
url = baseurl + ",2,"+str(i)+".html"
html = askUrl(url)
soup = BeautifulSoup(html, "html.parser")
print(soup)
2022年01月25日 08点01分
1
kw = parse.quote(parse.quote(input("请输入要搜索的岗位信息:")))
baseurl = "https://search.51job.com/list/000000,000000,0000,00,9,99," + kw
# url = baseurl + ",2,1.html"
# html = askUrl(url)
# print(html)
getData(baseurl)
# 制作URL网页
def askUrl(url):
head = {
"User-Agent": "Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko)Chrome / 97.0.4692.71Safari / 537.36"
}
request = urllib.request.Request(url, headers=head)
html = " "
try:
reponse = urllib.request.urlopen(request)
html = reponse.read()
except urllib.error.URLError as e:
if hasattr(e, "code"):
print(e.code)
if hasattr(e, "reason"):
print(e.reason)
return html
# 爬取网页--网页解析
def getData(baseurl):
datalist = []
for i in range(1, 10):
url = baseurl + ",2,"+str(i)+".html"
html = askUrl(url)
soup = BeautifulSoup(html, "html.parser")
print(soup)