python爬取出版社

2021-09-12 23:25:15 字數 531 閱讀 3167

爬取網頁中的出版社名稱

import urllib.request                 #匯入模組

data=urllib.request.urlopen("").read()

data=data.decode("utf-8") #解碼

import re #匯入正規表示式模組

pat='(.*?)

' #根據網頁源**編寫正規表示式

rst=re.compile(pat).findall(str(data))

print(rst)

fh=open("f:/file.txt","w") #將爬取內容寫入檔案中

for i in range(0,len(rst)):

fh.write(rst[i]+"\n") #換行顯示

fh.close() #關閉(儲存)檔案

新增出版社

views 定義增加出版社功能 def add publisher request if request.method post 獲取使用者提交的資料 pub name request.post.get pub name 判斷出版社名稱是否已存在 if models.publisher.object...

編寫Python爬蟲爬取豆瓣出版社列表並寫入檔案

本文介紹了如何編寫python程式從 爬取豆瓣出版社列表並寫入檔案 import requests,re from bs4 import beautifulsoup def gethtmltext url,code utf 8 try r requests.get url,timeout 30 r....

django2 登入與出版社

1.django核心功能 因為django功能很多 出版社可以使用到部分功能,最快最簡單了解django的執行模式,每個點後續細化去梳理 django的路由 django的檢視 django的模板 django的orm django的cookie與session django的中介軟體 django...