由于客户另外一些小需求转了500元,因此我赠送一个落地页,要求不是很高,可能后面还会转账一些来解决安卓苹果下载的问题,既然客户没有对界面特殊要求我就自由发挥了,先说好客户产品是五证齐全的正规麻将娱乐产品,不要想歪了,公安备案都是委托卓伊凡去帮忙提交的资料,你们也可以下载试玩,但是我根本看不懂,卓伊凡虽然是四川人但是根本不会打麻将,从小爹妈不让学,对了,本文是python爬虫有关,请合理合法使用,注意法律问题。
先问豆包要了一下最近比较火的落地页,
找我豆包的智能体,软件源码大全(卓伊凡)要网址,这一下给我来一堆太大的。
这回不错
时光序挺好看的,不过再看几个,
再次让给到发现这个酷我的下载页面很不错,稍微改一下是可用的
接下来正式开始,
思路如下
pip
安装 requests
和 BeautifulSoup
库。requests.get
发送 GET 请求并检查响应状态码。kuwo_down
。index.html
文件中。BeautifulSoup
解析 HTML 内容。urljoin
构建完整的 URL。urljoin
构建完整的 URL。新建download.py文件
安装依赖库
pip install requests beautifulsoup4
卓伊凡发现自己已经安装,只是提示升级
import os
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
\# 目标URL
url \= 'https://www.kuwo.cn/down'
\# 设置请求头,模拟浏览器请求
headers \= {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36'
}
\# 发送GET请求
response \= requests.get(url, headers\=headers)
response.raise\_for\_status() \# 检查请求是否成功
\# 创建保存目录
os.makedirs('kuwo\_down/css', exist\_ok\=True)
os.makedirs('kuwo\_down/js', exist\_ok\=True)
os.makedirs('kuwo\_down/assets', exist\_ok\=True)
\# 保存HTML文件
html\_file\_path \= os.path.join('kuwo\_down', 'index.html')
with open(html\_file\_path, 'w', encoding\='utf-8') as file:
file.write(response.text)
\# 解析网页内容
soup \= BeautifulSoup(response.content, 'html.parser')
\# 下载并保存CSS文件
css\_links \= soup.find\_all('link', rel\='stylesheet')
for link in css\_links:
css\_url \= urljoin(url, link\['href'\])
css\_response \= requests.get(css\_url)
css\_response.raise\_for\_status()
css\_file\_name \= os.path.basename(urlparse(css\_url).path)
css\_file\_path \= os.path.join('kuwo\_down/css', css\_file\_name)
with open(css\_file\_path, 'w', encoding\='utf-8') as file:
file.write(css\_response.text)
\# 下载并保存JS文件
js\_links \= soup.find\_all('script', src\=True)
for script in js\_links:
js\_url \= urljoin(url, script\['src'\])
js\_response \= requests.get(js\_url)
js\_response.raise\_for\_status()
js\_file\_name \= os.path.basename(urlparse(js\_url).path)
js\_file\_path \= os.path.join('kuwo\_down/js', js\_file\_name)
with open(js\_file\_path, 'w', encoding\='utf-8') as file:
file.write(js\_response.text)
\# 下载并保存图片等静态文件
static\_links \= soup.find\_all(\['img', 'link', 'script'\], src\=True)
for static in static\_links:
static\_url \= urljoin(url, static\['src'\])
static\_response \= requests.get(static\_url)
static\_response.raise\_for\_status()
static\_file\_name \= os.path.basename(urlparse(static\_url).path)
static\_file\_extension \= os.path.splitext(static\_file\_name)\[1\].lower()
if static\_file\_extension in \['.png', '.jpg', '.jpeg', '.gif', '.svg'\]:
static\_file\_path \= os.path.join('kuwo\_down/assets', static\_file\_name)
else:
continue \# 跳过非静态资源文件
with open(static\_file\_path, 'wb') as file:
file.write(static\_response.content)
print("网页内容下载完成!")
对应编写的python爬取代码,
执行后成功下载网页,但是我们发现有问题
资源方面都是成功下载了,包括css 和js,以及静态图片,但是首页代码奇乱,我怀疑这页面是vue写的,本地运行后显示也不对
赶紧查看下,果然是vue写的,所以vue是有好处的,编译后的文件让别人要仿你是很难的,我们需要换个目标站,这次卓伊凡会先检查下是否是vue。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。