76 except Exception as e:
77 table_hint = None
78 try:
79 table_sample_output = table_sample_output.i.previous.previous.previous
80 except Exception as e:
81 pass
82
83 # source
84 try:
85 table_source = table.find(text='Source').findNext('div', {'class':'panel_content'})
86 table_source.hidden = True
87 except Exception as e:
88 # print e
89 table_source = None
90
91 #recommend
92 try:
93 table_recommend = table.find(text='Recommend').findNext('div', {'class':'panel_content'})
94 table_recommend.hidden = True
95 except Exception as e:
96 # print e
97 table_recommend = None
98
99 # author
100 try:
101 table_author = table.find(text='Author').findNext('div', {'class':'panel_content'})
102 table_author.hidden = True
103 except Exception as e:
104 # print e
105 table_author = None
106
107
108
109
110 info = []
111
112
113 info.append(str(table_title))
114 info.append(str(table_limit_des))
115 info.append(str(table_problem_des))
116 info.append(str(table_input))
117 info.append(str(table_output))
118 info.append(str(table_sample_input))
119 info.append(str(table_sample_output))
120 info.append(str(table_hint))
121 info.append(str(table_author))
122 info.append(str(table_source))
123 info.append(str(table_recommend))
124 info.append(images)
125
126 return info
第二行 importurllib2 导入的是python的一个库
导入之后就能做 14行 content_stream = urllib2.urlopen(url) (打开网页)
15行 content = content_stream.read() (读取网页元素)
你甚至可以print content看一下 和那个网站下firebugs分析的数据一样
第四行 from BeautifulSoup importBeautifulSoup
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-33239-3.html
但发展方向是对的