VS2019python爬虫入门
2021-03-04 04:27
标签:strong bilibili app 程序包 odi python爬虫 执行 with open input 管理程序包,执行安装requests包命令 输入搜索关键词:爬虫 VS2019python爬虫入门 标签:strong bilibili app 程序包 odi python爬虫 执行 with open input 原文地址:https://www.cnblogs.com/ct-debug/p/14374859.htmlVS2019新建python项目
配置python环境
安装requests第三方库
pip install requests
导入第三方包
import requests
简单爬虫编写
import requests
if __name__ == "__main__":
kw = input(‘输入搜索关键词:‘)
url = ‘https://search.bilibili.com/all/‘
headers = {
‘user_agent‘:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36‘
}
data = {
‘keyword‘:kw
}
response = requests.get(url=url,params=data,headers=headers)
page_text = response.text
FileName = kw+‘.html‘
with open(FileName,‘w‘,encoding=‘utf-8‘) as fp:
fp.write(page_text)
print(FileName,‘成功!!‘)
测试
爬虫.html 成功!!
Press any key to continue . . .
下一篇:【Spring】动态代理模板