我的代码在这一行上给出了一个错误:tr_tag = soup.table.tr。
错误消息:非类型对象没有属性'tr'。
我正在imbd
上编写一个Web爬虫来使用Python 2.7获取数据。你能帮我解决一下吗?
def get_movie_data(self, soup, min_rating):
**tr_tag = soup.table.tr**
tr_next = tr_tag.next_sibling.next_sibling
data = []
movie_data = {}
while tr_next:
td = tr_next.contents[5]
name = self.get_movie_name(td)
def get_movie_data(self, soup, min_rating):
if soup.table:
tr_tag = soup.table.tr
tr_next = tr_tag.next_sibling.next_sibling
data = []
movie_data = {}
while tr_next:
td = tr_next.contents[5]
name = self.get_movie_name(td)
你能试试吗?