File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # coding=utf-8
3+
4+ import requests
5+ from bs4 import BeautifulSoup
6+ import time
7+
8+ def get_data (url ):
9+ req = requests .get (url )
10+
11+ soup = BeautifulSoup (req .text , 'lxml' )
12+ try :
13+ table = soup .select ("#ContentPlaceHolder1_lbldata table table" )[0 ].find_all ("td" )
14+ province = table [0 ].find ("b" ).string
15+ province = str (province )
16+ crop_name = str (table [6 ].string )
17+ crop_number = str (table [7 ].string )
18+ return province , crop_name , crop_number
19+ except :
20+ return False
21+
22+ if __name__ == "__main__" :
23+ for i in range (11 , 66 ):
24+ url = "http://202.127.42.157/moazzys/nongqing_result.aspx?year=2015&prov={}%20%20%20&item=01&type=1&radio=1&order1=year_code&order2=prov_code&order3=item_code" .format (i )
25+ result = get_data (url )
26+ if result :
27+ print (result )
28+ else :
29+ print ("hahha" )
30+ time .sleep (1 )
You can’t perform that action at this time.
0 commit comments