幫同學爬取某官方公眾號的眾多企業資訊
阿新 • • 發佈:2018-12-10
import requests
import xlwt
from bs4 import BeautifulSoup
from threading import Thread
# 725 1160
def main():
workbook = xlwt.Workbook()
sheet1 = workbook.add_sheet('test', cell_overwrite_ok=True)
first = 1
for i in range(725, 1161): # 分析資訊特點
response = requests.get("http://jingxinwei.wxshidai.com/jxj/style/detail?id=%d&redirect=1 "%i)
html = response.text
soup = BeautifulSoup(html, "html.parser")
print(i)
# myWorkbook = xlwt.Workbook()
w = 0
for i in soup.select(".answerDesc"): # 選擇標籤
d = i.get_text().strip() # 獲取標籤中的文字資訊
sheet1.write(first,w,d) # 寫入excel
w += 1
first += 1
workbook.save("data.xls")
t = Thread(target=main, args=())
t.start()