python简单爬虫课题_VS2019python爬虫入门
VS2019新建python項(xiàng)目
在vs2019中添加python編譯環(huán)境
創(chuàng)建python控制臺應(yīng)用程序項(xiàng)目
配置python環(huán)境
安裝requests第三方庫
管理程序包,執(zhí)行安裝requests包命令pip install requests
導(dǎo)入第三方包
import requests
簡單爬蟲編寫
import requests
if __name__ == "__main__":
kw = input(‘輸入搜索關(guān)鍵詞:‘)
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,‘成功!!‘)
測試
輸入搜索關(guān)鍵詞:爬蟲
爬蟲.html 成功!!
Press any key to continue . . .
總結(jié)
以上是生活随笔為你收集整理的python简单爬虫课题_VS2019python爬虫入门的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python处理脑电信号_用ICA去除脑
- 下一篇: 类的继承python 简明_[简明pyt