以下是实现的代码
from bs4 import BeautifulSoup
import requests
'''
def get_list_links():
num = input('page_num:')
for i in range(1, int(num) + 1):
list_urls = 'http://bj.58.com/pbdn/0/pn{}/'.format(i)
list_htmls = requests.get(list_urls)
list_soup = BeautifulSoup(list_htmls.text, 'lxml')
# print(list_soup) 没问题
list_links = list_soup.select('td.t > a.t')
# print(list_links) 没问题
for list_link in list_links:
link = list_link.get('href').split('?')[0]
return link
detail_html = requests.get(link)
detail_soup = BeautifulSoup(detail_html.text, 'lxml')
title = detail_soup.select('div.col_sub h1')[0].get_text()
print(title)
get_list_links()
'''
url = 'http://bj.58.com/pbdn/0/'
html = requests.get(url)
#print(html)
bsObj = BeautifulSoup(html.text, 'lxml')
#print(bsObj)
list_links = bsObj.select('td.t > a.t')
for list_link in list_links:
print(list_link)