|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
上源码
- import requests
- from bs4 import BeautifulSoup
- import openpyxl
- url = "https://www.gotohui.com/top/"
- headers = {
- 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
- }
- res = requests.get(url,headers=headers)
- soup = BeautifulSoup(res.text,'lxml')
- stable = soup.find("table",class_ = "stable")
- target = stable.find_all("tr")
- i=1
- name=[]
- num = []
- wb = openpyxl.Workbook()
- ws = wb.active
- for each in target:
- if i != 1:
- name.append(each.td.next_sibling.text)
- num.append(each.td.next_sibling.next_sibling.text)
- i = i+1
- ws.append(["城市","单价(元/㎡)"])
- for i in range(0,len(name)-1):
- ws.append([name[i], num[i]])
- wb.save("data.xlsx")
复制代码 |
|