python - Python 从网站获取特定数据
问题描述
我是 python 新手,我正在研究界面。我应该从 imdb 网站获取前 250 部电影。
def clicked(self):
movie=self.movie_name.text()
url="https://www.imdb.com/chart/top/"
response=requests.get(url)
html_content=response.content
soup=BeautifulSoup(html_content,"html.parser")
movie_name = soup.find_all("td",{"class":"titleColumn"})
for i in movie_name:
i=i.text
i=i.strip()
i=i.replace("\n","")
if (movie == i):
self.yazialani.setText(i)
使用此代码输出如下: 6. 辛德勒的名单 (1993) 7. 指环王:王者归来 (2003) 8. 低俗小说 (1994) 但对于我的项目,我只想取电影名称年和排名。我应该如何更改我的代码?
解决方案
一种原始的解决方案可能是(考虑到你的字符串是小费digits
+ .
+ name_of_movie
+(YEAR)
只是
a=["6. Schindler's List(1993)", "7. The Lord of the Rings: The Return of the King(2003)", "8. Pulp Fiction(1994)"]
just_names=[]
for name in a:
i=0
while True:
if name[i]=='.':
just_names.append(name[i+2:-6]) # To delete the space after the point
break
i+=1
推荐阅读
- vba - 更新报表的属性 - OrderBy 和 Filter
- powershell - Get-WSManInstance 忽略 -ErrorAction 参数
- apache-superset - 在 Windows Server 2019 上安装 Apache Superset,并将 Superset 与 MSSQL 连接
- python - 如何在 wx.media.MediaCtrl python 中加载后立即播放文件?
- reactjs - 将 ReactComponent 作为引用存储在对象的属性中
- c++ - 初始化 std::array
- android - 运行大小超过 2GB 的 apk 文件时崩溃
- python-3.x - 使用一个月中的特定日期获取另一列的总数?
- javascript - 如何在 Meteor.js 中设置登录会话超时?
- powershell - 在 Powershell 中进行一次 foreach 迭代而不是 4 次