Quanzhou popular attractions and Price

Requests Import
from the BeautifulSoup BS4 Import
Import PANDAS AS PD
from PANDAS Import DataFrame
URL = "https://travelsearch.fliggy.com/index.htm?searchType=product&keyword=%E6%B3%89%E5%B7%9E%E6% 99% AF% E7% 82% B9 "# crawling on the flying pig Quanzhou interest information
headers = { 'User-Agent' : 'Mozilla / 5.0 (Windows NT 6.3; Win64; x64) AppleWebKit / 537.36 (KHTML, like Gecko) the Chrome / 69.0.3497.100 Safari / 537.36 '} #
R & lt requests.get = (URL) request site #
r.encoding = r.apparent_encoding # Unicode
Data = r.text
Soup = the BeautifulSoup (Data,' html.parser ') # use "delicious soup" tool
print (soup.prettify ()) # display site structure
Scenery = [] # create an empty list
. price = []
Grade = []
for i in soup.find_all (class _ = "main-title") : # name added to the attractions empty list
    Scenery.append (i.get_text ().strip())
for k in soup.find_all (class _ = "price"): # add attraction tickets prices into an empty list
    price.append (k.get_text () Strip ().)
for G in soup.find_all (class _ = "Tag-List clear-fix "): # add level of interest into an empty list
    Grade.append (g.get_text () Strip ()).
Data = [Scenery,. price, grade]
Print (Data)
S = pd.DataFrame (Data, index = [ "attractions name", "attraction ticket prices", "attraction level"])
Print (sT) # data visualization

Guess you like

Origin www.cnblogs.com/cmmmmm/p/12533859.html