Crawl 58 second-hand phone in the same city the contents of the corresponding detail page of a list page

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.