1

import requests
from bs4 import BeautifulSoup
import time
import lxml
def run():
url=“http://www.4399.com”
headers={
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36”
}
page_text = requests.get(url=url, headers=headers)
page_text.encoding = ‘gb2312’
soup = BeautifulSoup(page_text.text, ‘lxml’)
g_list=soup.select(".tm_list>li>a")
print(“正在为你推荐以下好玩的游戏…”)
# time.sleep(3)
n=0
g_url=[]
for i in g_list:
n+=1
print(f"{n}.{i.text}")

    #
    if i['href'][:3]=='//w':
        g_url.append(i['href'][2::])
    elif i['href'][:2]=="//":
        g_url.append(f"http://www.4399.com/{i['href'][2::]}")
    elif i['href'][:1]=="/":
        g_url.append(f"http://www.4399.com/{i['href'][1::]}")
    elif i['href'][:3]=="htt":
        g_url.append(i['href'])
    else:
        g_url.append(f"http://www.4399.com/{i['href']}")
select=int(input("请选择").strip())
get(g_url[select])

def get(surl):
url=surl
headers={
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36”
}
page_text = requests.get(url=url, headers=headers).text
soup = BeautifulSoup(page_text, ‘lxml’)
g_play=soup.select(".play>a")
print(g_play)
if name==“main”:
run()

上一篇:Actuator


下一篇:JS获取浏览器高度和宽度