45 行
1.6 KiB
Python
45 行
1.6 KiB
Python
import requests
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
def webstack():
|
|
url = "http://webstack.cc/cn/"
|
|
html = requests.get(url)
|
|
# print(html.text)
|
|
doc = html.text
|
|
|
|
soup = BeautifulSoup(doc,"html.parser")
|
|
# print(soup.select('div.col-sm-3'))
|
|
list = []
|
|
sql = '''
|
|
INSERT into library (name,summary,url,img)
|
|
values ()
|
|
'''
|
|
for item_html in soup.select('div.col-sm-3'):
|
|
# print(type(item_html))
|
|
# print(item_html.select('div.label-info')[0].get("data-original-title"))
|
|
# print("http://webstack.cc/"+item_html.select('img.img-circle')[0].get("data-src").replace("..",""))
|
|
# print(item_html.select("a.overflowClip_1")[0].text.replace("\r\n","").replace(" ","").replace("\n",""))
|
|
# print(item_html.select("p.overflowClip_2")[0].text)
|
|
url = item_html.select('div.label-info')[0].get("data-original-title")
|
|
img = "http://webstack.cc/"+item_html.select('img.img-circle')[0].get("data-src").replace("..","")
|
|
title = item_html.select("a.overflowClip_1")[0].text.replace("\r\n","").replace(" ","").replace("\n","")
|
|
summary = item_html.select("p.overflowClip_2")[0].text
|
|
list.append({"title":title,"img":img,"url":url,"summary":summary})
|
|
sql += "('"+title+"','"+summary+"','"+url+"','"+img+"'),"
|
|
|
|
print(len(list))
|
|
print(sql)
|
|
|
|
sql = '''
|
|
INSERT into library (cate,name,summary,url,img)
|
|
values ()
|
|
'''
|
|
|
|
with open('site.txt','r') as f:
|
|
for line in f.readlines():
|
|
print(line.split(","))
|
|
sql += "('"+line.split(",")[0]+"','"+line.split(",")[1]+"','"+line.split(",")[2]+"','"+line.split(",")[4]+"','"+line.split(",")[3]+"'),"
|
|
print(sql) |