Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import requests
- from bs4 import BeautifulSoup
- url = "http://www.pga.com/golf-courses/search?searchbox=Course+Name&searchbox_zip=ZIP&distance=50&price_range=0&course_type=both&has_events=0"
- r = requests.get(url)
- soup = BeautifulSoup(r.content)
- g_data1=soup.find_all("div",{"class":"views-field-nothing-1"})
- g_data2=soup.find_all("div",{"class":"views-field-nothing"})
- for item in g_data1:
- try:
- print item.contents[1].find_all("div",{"class":"views-field-counter"})[0].text
- except:
- pass
- try:
- print item.contents[1].find_all("div",{"class":"views-field-course-type"})[0].text
- except:
- pass
- for item in g_data2:
- try:
- print item.contents[1].find_all("div",{"class":"views-field-title"})[0].text
- except:
- pass
- try:
- print item.contents[1].find_all("div",{"class":"views-field-address"})[0].text
- except:
- pass
- try:
- print item.contents[1].find_all("div",{"class":"views-field-city-state-zip"})[0].text
- except:
- pass
- output:
- /home/martin/dev/python/pga_golf_course.py:7: UserWarning: No parser was explicitly specified,
- so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem,
- but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
- The code that caused this warning is on line 7 of the file /home/martin/dev/python/pga_golf_course.py.
- To get rid of this warning, pass the additional argument 'features="lxml"' to the BeautifulSoup constructor.
- soup = BeautifulSoup(r.content)
- [Finished in 0.508s]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement