资源简介
该程序实现了对58同城的商品信息进行爬取。
代码片段和文件信息
from bs4 import BeautifulSoup
import requests
import time
url = ‘http://bj.58.com/pingbandiannao/24604629984324x.shtml‘
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text‘lxml‘)
def get_links_from(who_sells):
urls = []
list_view = ‘http://bj.58.com/pbdn/{}/pn2/‘.format(str(who_sells))
wb_data = requests.get(list_view)
soup = BeautifulSoup(wb_data.text‘lxml‘)
for link in soup.select(‘td.t a.t‘):
urls.append(link.get(‘href‘).split(‘?‘)[0])
return urls
def get_views_from(url):
id = url.split(‘/‘)[-1].strip(‘x.shtml‘)
api = ‘http://jst1.58.com/counter?infoid={}‘.format(id)
# 这个是找到了58的查询接口,不了解接口可以参照一下新浪微博接口的介绍
js = requests.get(api)
- 上一篇:最小二乘法python代码,不用库函数
- 下一篇:蚁群算法的python代码
评论
共有 条评论