
python
goxingman
这个作者很懒,什么都没留下…
展开
-
python爬虫7:完整的一个爬虫小demo
from bs4 import BeautifulSoup import re import urllib.request import xlwt import sqlite3 import ssl ssl._create_default_https_context = ssl._create_unverified_context def main(): #网址就不说了,避免侵权 baseUrl = "xxxxxx" data = getData(baseUrl) # saveD.原创 2021-12-16 09:30:16 · 1448 阅读 · 0 评论 -
python爬虫6:将数据保存到数据库
注意: 1、切记一定要commit() ,否则存不到数据库 2、可以多条execute() 然后一次性commit() 3、使用完后记得close() import sqlite3 def saveDataToDB(data): connect = sqlite3.connect("test.db") c = connect.cursor() #获取游标 # i=1 # for title in data: # sql = r"insert i.原创 2021-12-16 09:28:10 · 1118 阅读 · 0 评论 -
python爬虫5:xlwt的使用保存到excel
import xlwt def saveDataToExcel(): workbook = xlwt.Workbook(encoding="utf-8") sheet = workbook.add_sheet("sheet1") sheet.write(0,0,"ttt") workbook.save("te.xls") saveDataToExcel()原创 2021-12-16 09:23:58 · 1093 阅读 · 0 评论 -
python爬虫4:正则使用
import re def test(): rg = "ff" file = open("./tb.html", "rb") html = file.read() # 组合找 re_compile = re.compile(rg) search = re_compile.search("gsfgdffgfdg") #直接找 re_search = re.search("ff", "gsfgdffgfdg") #查找全部 通过在 .原创 2021-12-16 09:22:46 · 478 阅读 · 0 评论 -
python爬虫3:bt4的使用
import bs4 import re def getData(): file = open("./tb.html", "rb") html = file.read() soup = bs4.BeautifulSoup(html, "html.parser") #获取所有标签 fd = soup.find_all() #获取某个标签内容 (只取第一个此标签) div = soup.div div = soup.div.string .原创 2021-12-16 09:19:41 · 562 阅读 · 0 评论 -
python爬虫2:urllib使用
注意,导包时候要导入urllib.request,只导urllib可能会报错 import urllib.request #get请求 rep = urllib.request.urlopen("http://www.baidu.com") print(rep.read().decode("utf_8")) #post请求 a = bytes(urllib.parse.urlencode({}),encoding="utf-8") rsp = urllib.request.urlopen("htt.原创 2021-12-16 09:18:23 · 222 阅读 · 0 评论 -
python爬虫1:基础环境配置
1、首先电脑安装python环境 2、下载pyCharm(推荐,这个软件很好用) 3、按我剪头指的地方可以一步一步到安装第三方库的地方,另外可以配一下国内仓库,装的快点 (这里其实相当于在命令行pip install xxx) 配置国内仓库方法:可以用这个库(Simple Indexhttps://pypi.tuna.tsinghua.edu.cn/simple/) 4.搜索安装第三方库:bs4、xlwt 接下来就可以开发了,请移步下一篇 ...原创 2021-12-15 17:19:08 · 759 阅读 · 0 评论 -
python基础语法学习笔记
#a = type(1) #a = id('a') a = int('123') print(a) #占位符 #a="heill" #b="fff %s" %a #c=f"hhh {b}" #print(c) #and or not #三元运算符 语句1 if 判断 else 语句2 a=10; b=20; print('a大') if a>b else print('b大') #代码块 #if 条件: # 代码块 if(True): print(12) print(23) .原创 2021-12-09 13:59:02 · 113 阅读 · 0 评论