Collect dealer information on the official Beijing Automotive website (parsing html tags)

Source: Internet
Author: User

1. The website address http://www.baicmotor.com/dealer.php

2. After using firefox to view the information, I found that the website does not use json data, but is simply an html page.

3. Use pyquery in the PyQuery library for html Parsing

Page Style:

  

Code:

                    css_select =                   page =                  page = page.replace(,         page = page.replace(,                           d =                  dealer_list =                   dealer_div                           p = dealer_div.findall(                          dealer =                           len(p)==1                                                 len(p)==6                 strp =                 dealer[Constant.CITY] = p[1                 strc = p[2                                  dealer[Constant.PROVINCE] =                 dealer[Constant.CITY] = p[1                 dealer[Constant.NAME] = p[2                 dealer[Constant.ADDRESSTYPE] = p[3                 dealer[Constant.ADDRESS] = p[4                 dealer[Constant.TELPHONE] = p[5               len(p)==5                  p[0].text.strip() != u                     dealer[Constant.PROVINCE] =                     dealer[Constant.CITY] =                     dealer[Constant.NAME] = p[1                     dealer[Constant.ADDRESSTYPE] = p[2                     dealer[Constant.ADDRESS] = p[3                     dealer[Constant.TELPHONE] = p[4               len(p)==3                                      self.saver.commit()

4. The final code is successfully executed. The corresponding data is obtained and saved to excel.

 

Related Article

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.