Quanzhou popular attractions and Tours

Import tool reptiles

Right-click View Source Source code

Find crawling data

Import Requests
 from BS4 Import the BeautifulSoup
 Import PANDAS AS PD
 from PANDAS Import DataFrame 
UR1 = ' https://www.mafengwo.cn/jd/11246/gonglve.html ' # open the page 
headers = { ' the User-- Agent ' : ' the Mozilla / 5.0 (the Windows NT 6.3; Win64; x64-) AppleWebKit / 537.36 (KHTML, like the Gecko) the Chrome / 69.0.3497.100 Safari / 537.36 ' } #
 R & lt requests.get = (UR1, headers = headers) # request website 
r.encoding = r .apparent_encoding # Unicode 
data =r.text 
Soup = the BeautifulSoup (Data, ' html.parser ' ) # use "tasty soup" tool 
Print (soup.prettify ()) # display the site configuration 
title = [] 
midlle = []
 for I in soup.find_all ( = class_ " title " ): # the popular attractions into an empty list 
    title.append (i.get_text () Strip ()).
 for k in soup.find_all (class_ = " Middle " ): # put into the empty Tours list 
    midlle.append (k.get_text (). Strip ()) 
Data =[title,midlle]
print(data)

 

Guess you like

Origin www.cnblogs.com/48520-xc/p/12526755.html