Project Introduction:
Write a Python script to crawl the listings of a rental site, using the top of the JS API on the map to mark the location of the listing, the distance from the work place within 1 hours to reach the range, attached to the bus path planning function to view the time of different paths.
First, Introduction
1. Background
The project comes from a rental of the history of Tears (exaggeration): This is the case, the author is going to go to graduate school, and the roommate is graduating in the search for a job, plainly, there is no money, so intend to co-rent. Because of the poor, it is impossible to find a store intermediary, only to see the market, 58 and some rental app. The period needs to consider two people's commuting range to choose a lot, because of the traffic is not familiar with, only choose their own near the more expensive lot, spend a lot of time to read the market or 58 of personal listings information, but the personal housing information is still flooded with a large number of intermediaries, holding a little hope to make a few calls, The answer is that the price is not rented at all, and then high also can not be rented (most of the listing information does not match). Finally in the dormitory closed one weeks before the rent to a cost-effective also can partition. After all, the partition is not convenient, so plan to find a job after the roommate to change a new place, so there is this rental script and tutorial. (Tutorial address: https://www.shiyanlou.com/courses/599)
I believe there are a lot of fresh graduates may encounter the same situation, I hope this tutorial can really help everyone, perhaps not only in the rental area.
Summarize the crux of the problem of renting:
1. No money
2. Small intermediary release of the price is generally false, will waste you a lot of time
3. Not familiar with the traffic route so that the choice of narrow surface
4. If you have more than one person, you have to consider commuting time for multiple people
Issues that this tutorial will address:
1. Learn the technology, increase knowledge, you can find a good job, find a good job can be rich
2. This selection of listings from 58 of the brand apartment pavilion, so there is no such a small intermediary, price for me and my roommate can accept. In fact, you can do a classifier filter market on the intermediary to find low-priced personal listings, the need for students can try
3. The commute area is circled on the map to solve the problem of unfamiliar traffic routes.
4. This course is a single-player version, but it can be used when you delete a statement in the code (but the function of path planning is only for one person). It is better to open more than one page if you use it directly.
The end result is as follows:
Because the front-end compatibility is not done, the upper right corner is collapsed. Self-used gadgets actually do not have to look good, efficiency first.
, a large blue color block is the area within an hour's drive from the work place. The blue mark is the listing, and the path plan and the address of the property are automatically given when clicked. The red mark (not "final") is the work place, which was blocked in the these drawings. The input box of the work place has the function of automatic completion, it is also very convenient. As for the listing document, we will create a Python script to crawl the listing information.
2. Knowledge points
During the completion of this tutorial project, we will learn:
Simple use of 1.requests, BeautifulSoup, CSV and other libraries
2. Use of the German map Javascript API
Second, the experimental environment
Open the terminal, go to the Code directory, create the Rent_proj folder, and use it as our working directory.
&& CD Rent_proj
To install the required libraries:
$ sudo apt-get install PYTHON-BS4
Three, the principle of experiment
Three files are used in the experiment: Crawl.py,rent.csv and index.html, where Rent.csv is generated by crawl.py and is a listing file. Crawl.py is a very simple script to crawl Web pages.
Index.html is the most important part of displaying the map. The process is implemented in the following general steps:
Why don't I put the JS code and CSS code out of the index.html, how to write a script how to get good.
Iv. Demonstration of Effect
Start by choosing a location to work out the commute within an hour:
Beijing traffic jam is too rampant, may also be Metro insurance:
After importing the listing file:
Choosing a listing will automatically help you plan your route:
Select the location to jump to the target page:
Wayne Shi
Source: Know
Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source
Python Learning Exchange Group: 238757010
Api+python to solve the problem of renting