登录 注册
当前位置:主页 > 资源下载 > 40 > 利用Python抓取淘宝商品数据

利用Python抓取淘宝商品数据

  • 更新:2024-12-15 23:14:50
  • 大小:1KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:专业指导 - 课程资源
  • 格式:PY

资源介绍

import requests from bs4 import BeautifulSoup import bs4 def getHTMLText(url): try: r = requests.get(url, timeout=30) r.raise_for_status() r.encoding = r.apparent_encoding return r.text except: return "" def fillUnivList(ulist, html): soup = BeautifulSoup(html, "html.parser") for a in soup.find('tbody').children: if isinstance(a, bs4.element.Tag): tds = a('td') ulist.append([tds[0].string, tds[1].string, tds[2].string, tds[3].string]) def printUnivList(ulist, num): print("{:^10}\t{:^6}\t{:^6}\t{:^16}".format("排名","学校名称","地区","总分")) for i in range(num): u=ulist[i] print("{:^10}\t{:^6}\t{:^6}\t{:^16}".format(u[0],u[1],u[2],u[3]))