Scrapping data from html table, selecting elements between titles

edyvedy13

I am trying to scrape information from the following url:http://www.mobygames.com/game/xbox360/wheelman/credits with this code;

# Imports
import requests
from bs4 import BeautifulSoup
credit_link = "http://www.mobygames.com/game/xbox360/wheelman/credits"
response = requests.get(credit_link)
soup = BeautifulSoup(response.text, "lxml")
credit_infor= soup.find("div", class_="col-md-8 col-lg-8")
credit_infor1 = credit_infor.select('table[summary="List of Credits"]')[0].find_all('tr')

This is the format that I need to get:

info          credit_to  studio                   game       console
starring      138920     starring                 Wheelman   Xbox 360
Studio Heads  151851     Midway Newcastle Studio  Wheelman   Xbox 360
Studio Heads  73709      Midway Newcastle Studio  Wheelman   Xbox 360

Where info corresponds to first "td" in each row, credit_to corresponds to id of particular contributor (e.g. 138920 is id of Vin Diesel) starring corresponds to titles. I think I can handle everything except getting studio name (i.e. titles) near each row (it will be switched from Midway Newcastle Studio to San Diego QA Team later and so on). How could I do it?

Keyur Potdar

According to your program, credit_infor1 will have a list of all tr tags (rows). If you check the HTML, the rows that have the title (studio) in them, they don't have a class attribute. For all the other rows, they have class="crln" attribute.

So, you can iterate over all the rows and check if the current row has class as an attribute using the has_attr() function (which is somewhat hidden in the docs). If the attribute is not present, change the title, else continue with the scraping of other data.

Continuing your program:

studio = ''
for row in credit_infor1:
    if not row.has_attr('class'):
        studio = row.h2.text
        continue

    # get other values that you want from this row below

    info = row.find('td').text
    # similarly get all the other values you need each time

    print(info + ' | ' + studio)

Partial output:

Starring | Starring
Studio Heads | Midway Newcastle Studio
Executive Producers | Midway Newcastle Studio
Technical Directors | Midway Newcastle Studio
Lead Programmers | Midway Newcastle Studio
...
QA Manager | San Diego QA Team
Compliance QA Manager | San Diego QA Team
QA Data Analyst | San Diego QA Team
...
SQA Analyst | SQS India QA
QA Team | SQS India QA
Executive Producers | Tigon Studios
Head of Game Production | Tigon Studios
...

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

From list to data frame with tidyverse, selecting specific list elements

分類Dev

MySQL nodejs crash upon selecting data from big table

分類Dev

Selecting data from another SQL table to add to string text

分類Dev

How to add spacing between elements of bootstrap enabled html table?

分類Dev

Selecting columns from a table in memory

分類Dev

Selenium - Selecting an item from dropdown list if the values are inside <table> tags and NOT under <option> in html

分類Dev

Add html element between elements in sequence generated from range

分類Dev

How to get data from columns of a table in HTML

分類Dev

How to get data from columns of a table in HTML

分類Dev

Pulling data from database and into an html table

分類Dev

Problem with saving data from a html form (using Thymeleaf) that has a foreign key relation between two table with Spring and JPA annotations

分類Dev

Selecting a max value from a pivot table

分類Dev

php selecting an order from a different mysql table

分類Dev

Selecting table elements and calculating total value using Jquery/Javascript

分類Dev

How to get data from dynamic elements that added to the html page?

分類Dev

selecting a specific value from a data frame

分類Dev

Error after selecting data from database

分類Dev

Selecting from a table based on value in a foreign table rails

分類Dev

Elements are not visible after selecting items from dropdown in android app

分類Dev

How to Display data from moodle database in an html table

分類Dev

How to export data from HTML table to excel using angularjs

分類Dev

Get titles from Wikipedia

分類Dev

Segue between multiple detail views when selecting from tableview

分類Dev

How to split elements inside <p> tag while web scrapping

分類Dev

SQL Server insert EXCEPT without selecting from a table

分類Dev

Best way of selecting 8k+ rows from a table

分類Dev

Get HTML content between 2 elements

分類Dev

How modify the content of a html table with with a ng-click event outside the table that get data from a RESTFUL API

分類Dev

How can I select data from a mysql table, and then throw it into a html table

Related 関連記事

  1. 1

    From list to data frame with tidyverse, selecting specific list elements

  2. 2

    MySQL nodejs crash upon selecting data from big table

  3. 3

    Selecting data from another SQL table to add to string text

  4. 4

    How to add spacing between elements of bootstrap enabled html table?

  5. 5

    Selecting columns from a table in memory

  6. 6

    Selenium - Selecting an item from dropdown list if the values are inside <table> tags and NOT under <option> in html

  7. 7

    Add html element between elements in sequence generated from range

  8. 8

    How to get data from columns of a table in HTML

  9. 9

    How to get data from columns of a table in HTML

  10. 10

    Pulling data from database and into an html table

  11. 11

    Problem with saving data from a html form (using Thymeleaf) that has a foreign key relation between two table with Spring and JPA annotations

  12. 12

    Selecting a max value from a pivot table

  13. 13

    php selecting an order from a different mysql table

  14. 14

    Selecting table elements and calculating total value using Jquery/Javascript

  15. 15

    How to get data from dynamic elements that added to the html page?

  16. 16

    selecting a specific value from a data frame

  17. 17

    Error after selecting data from database

  18. 18

    Selecting from a table based on value in a foreign table rails

  19. 19

    Elements are not visible after selecting items from dropdown in android app

  20. 20

    How to Display data from moodle database in an html table

  21. 21

    How to export data from HTML table to excel using angularjs

  22. 22

    Get titles from Wikipedia

  23. 23

    Segue between multiple detail views when selecting from tableview

  24. 24

    How to split elements inside <p> tag while web scrapping

  25. 25

    SQL Server insert EXCEPT without selecting from a table

  26. 26

    Best way of selecting 8k+ rows from a table

  27. 27

    Get HTML content between 2 elements

  28. 28

    How modify the content of a html table with with a ng-click event outside the table that get data from a RESTFUL API

  29. 29

    How can I select data from a mysql table, and then throw it into a html table

ホットタグ

アーカイブ