Originally is based on the tutorial is to distinguish between individuals and businesses, but the tutorial is the 15 58 of the same city website has been revised, personal second-hand items when the jump to turn, the merchant is still in 58, so two Details page label no longer universal, not the implementation of personal and business page jump. The code is as follows:
From BS4 import BeautifulSoup
Import requests
Import time
url = ' http://zhuanzhuan.58.com/detail/883905856824967177z.shtml '
def get_links_from (who_sells):
URLs = []
List_view = ' http://bj.58.com/shouji/{}/'. Format (str (who_sells))
Web_date = Requests.get (List_view)
Soup = BeautifulSoup (web_date.text, ' lxml ')
For link in soup.select (' td.t a.t '):
Urls.append (Link.get (' href '))
return URLs
def get_info (who_sells=0):
URLs = Get_links_from (who_sells)
For URL in URLs:
web_date = requests.get (URL)
Soup = BeautifulSoup (web_date.text, ' lxml ')
data = {
' title ': Soup.title.text,
' Price ': soup.select (' Span.price_now ') [0].text if Soup.find_all (' span ', ' price_now ') Else None,
' Area ': Soup.select (' Div.palce_li > Span > I ') [0].text if Soup.find_all (' div ', ' palce_li ') Else None,
' Catr ': ' personal ' if who_sells==0 Else ' merchant ',
' View ': None,
}
Print (data)
Get_info ()
Crawl 58 second-hand phone in the same city the contents of the corresponding detail page of a list page