【问题标题】:get user_id, rating from webscraping pictures从网络抓取图片中获取用户 ID、评分
【发布时间】:2018-08-08 11:17:47
【问题描述】:

我有一个来自网络的数据框,它从网站animeka 网站上抓取所有页面:

import pandas as pd 
import requests
from bs4 import BeautifulSoup

for page_no in range(1, 467):
    url = 'http://www.animeka.com/animes/~_{}.html'.format(page_no)

    titles, studios, genres, durations = [], [], [], []

for page_no in range(1, 467):
    url = 'http://www.animeka.com/animes/~_{}.html'.format(page_no)
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'html.parser')

    for table in soup.find_all('table', class_='animesindex'):
        td = table.find_all('td', class_='animestxt')
        titles.append(td[1].text.split(':')[1])
        studios.append(td[3].text.split(':')[1])
        genres.append(td[4].text.split(':')[1])
        durations.append(td[6].text.split(':')[1])

headers = ['Title', 'Studio', 'Genres', 'Duration']
df = pd.DataFrame(dict(zip(headers, [titles, studios, genres, durations])))
df = pd.DataFrame({'duration':df["Duration"], "genre" : df["Genres"], 'studio':df["Studio"], "titre" : df["Title"]})

我想获得他们为每部动画设置的 user_id 和评级,但这是在“详细”小节中的图片,我不知道如何收集这些信息。

这是一个图片代码,其中评分是:

<img src="/animes/13498.png" width="400" height="100" alt="graph">

【问题讨论】:

  • 那么,您的问题是——如何从图像中提取信息?

标签: python pandas web-scraping beautifulsoup


【解决方案1】:

您可以使用find_previous 方法来查找文档中特定标签之前的标签和字符串。

td[1].find_previous('td')

所以,如果你想提取图像的名称,你可以试试这个:

td[1].find_previous('td').img['src'].split('/')[-1]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    相关资源
    最近更新 更多