前言:刚开始学python,作为一个新手写了这么一个小玩意,本着大家一起学习的精神,分享出来,大佬看看笑笑就好;由于受易语言影响太深了,很多代码逻辑还是停留在易语言的风格上,举个栗子,需要叠加:E:i=i+1 p: i +=;代码预览载入e是空格,p是回车,很多很多~矫正太难了,慢慢习惯吧~再次强调一下昂,大佬看看就好,新手勿喷~
[Python] 纯文本查看复制代码
import requests
from bs4 import BeautifulSoup
import re
from urllib import parse
header = {
"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36"
}
findRegID = re.compile(r'data-val="(\d+)">(.*?)</div>')
findRegtpye = re.compile(r'data-val="\d+">(.*?)</div>')
def main():
cheack()
while True:
reg = input("请输入大区ID,比如是艾欧尼亚,请输入1 \n" )
if reg == "":
print("游戏大区不能为空")
pID = input("请输入游戏ID: \n")
if pID == "":
print("游戏ID不能为空!")
else:
print(pID,reg)
go(pID,reg)
#(response)
def go(pID,reg):
pID = parse.quote(pID, encoding="utf-8")
url = "https://www.lolhelper.cn/rank_lcu.php?gameid=" + pID + "&server="+str(reg)
print(url)
response = requests.get(url=url, headers=header)
response = response.text
soup = BeautifulSoup(response, 'lxml')
for item in soup.find_all("div", class_="main_item"):
res = item.text
res = res.replace('\n', '')
print(res)
#获取大区数据
def getReg():
url = 'https://www.lolhelper.cn'
response = requests.get(url = url,headers = header)
response = response.text
soup = BeautifulSoup(response,'lxml')
list = []
for item in soup.find_all('div',class_="option_sel_item"):
item = str(item)
reg = re.findall(findRegID,item)
list.append(reg)
# Name = re.findall(findRegName,item)
# print(Name)
#print(str(ID)+"."+Name)
return list
#检测展示大区数据
def cheack():
allReg = getReg()
allReglen = len(allReg)
print("发现大区%d个\n" % allReglen)
tupall=''
for item in allReg:
allRegCan = item[0]
tup = allRegCan[0] + "." + allRegCan[1]
tupall = tupall +tup
print(tupall)
# print("发现大区%d个! " % allReglen)
if __name__ == "__main__":
main()