python简单爬虫课题_VS2019python爬虫入门
VS2019新建python項目
在vs2019中添加python編譯環境
創建python控制臺應用程序項目
配置python環境
安裝requests第三方庫
管理程序包,執行安裝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 . . .
總結
以上是生活随笔為你收集整理的python简单爬虫课题_VS2019python爬虫入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python处理脑电信号_用ICA去除脑
- 下一篇: js怎么判断浏览器内核版本号(js怎么判