使用BeautifulSoup网站抓取IMDb页面

帕特里克·李

我是WebScraping / Python和BeautifulSoup的新手,并且很难使我的代码正常工作。

我想抓取网址:http : //m.imdb.com/feature/bornondate,以获取:

  • 名人姓名
  • 名人形象
  • 职业
  • 最佳作品

该页面上的十位名人。我不确定自己在做什么错。

这是我的代码:

import urllib2
from bs4 import BeautifulSoup

url = 'http://m.imdb.com/feature/bornondate'

test_url = urllib2.urlopen(url)
readHtml = test_url.read()
test_url.close()

soup = BeautifulSoup(readHtml)
# Using it track the number of Actor
count = 0
# Fetching the value present within tag results
person = soup.findChildren('section', 'posters list')
# Changing the person into an iterator
iterperson = iter(person[0].findChildren('a'))

# Finding 'a' in iterperson. Every 'a' tag contains information of a person
for a in iterperson:
    imgSource = a.find('img')['src'].split('._V1.')[0] + '._V1_SX214_AL_.jpg'
    person = a.findChildren('div', 'label')
    title = person[0].find('span', 'title').contents[0]
    ##profession = person[0].find('div', 'detail').contents[0].split(,)
    ##bestWork = person[0].find('div', 'detail').contents[1].split(,)

    print '*******************************IMDB People Born Today***********************************'
    # Printing the S.No of the person
    print 'S.No. --> ',
    count += 1
    print count
    # Printing the title/name of the person
    print 'Title --> ' + title
    # Printing the Image Source of the person
    print 'Image Source --> ', imgSource
    # Printing the Profession of the person
    ##print 'Profession --> ', profession
    # Printing the Best work of the person
    ##print 'Best Work --> ', bestWork

目前,什么都没有打印出来。另外,如果这个含糊不清,您能解释一下如何做例如名人名吗?

如果有帮助,这是第一位名人的html代码:

<section class="posters list">
<h1>March 7</h1>

    <a href="/name/nm0186505/" class="poster "><img src="http://ia.media-imdb.com/images/M/MV5BMTA2NjEyMTY4MTVeQTJeQWpwZ15BbWU3MDQ5NDAzNDc@._V1._CR0,0,1369,2019_SX40_SY59.jpg" style="background:url('http://i.media-imdb.com/images/mobile/people-40x59-fade.png')" width="40" height="59"><div class="label"><span class="title">Bryan Cranston</span><div class="detail">Actor, "Ozymandias"</div></div></a>
ec

首先,IMDb “使用条件”明确禁止刮屏

机械手和屏幕抓取:未经以下明确的书面同意,您不得在本网站上使用数据挖掘,机械手,屏幕抓取或类似的数据收集和提取工具。

尝试探索IMDb JSON API而非网络抓取方法。


您当前的问题是-在特定日期出生的人员列表是通过IMDbAPI单独调用以及所涉及javascript逻辑加载的

现在最简单的选择是切换到selenium浏览器自动化工具。使用无头PhantomJS浏览器的工作示例

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.PhantomJS()
driver.get("http://m.imdb.com/feature/bornondate")

# waiting for posters to load
wait = WebDriverWait(driver, 10)
posters = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "section.posters")))

# extracting the data poster by poster
for a in posters.find_elements_by_css_selector('a.poster'):
    img = a.find_element_by_tag_name('img').get_attribute('src').split('._V1.')[0] + '._V1_SX214_AL_.jpg'

    person = a.find_element_by_css_selector('div.detail').text
    title = a.find_element_by_css_selector('span.title').text

    print img, person, title

印刷:

http://ia.media-imdb.com/images/M/MV5BMTA2NjEyMTY4MTVeQTJeQWpwZ15BbWU3MDQ5NDAzNDc@._V1_SX214_AL_.jpg Actor, "Ozymandias" Bryan Cranston
http://ia.media-imdb.com/images/M/MV5BNjUxNjcxMjE4N15BMl5BanBnXkFtZTgwNDk4NjA2MzE@._V1_SX214_AL_.jpg Actress, "Karla" Laura Prepon
http://ia.media-imdb.com/images/M/MV5BMTQ4MzM1MDAwMV5BMl5BanBnXkFtZTcwNTU4NzQwMw@@._V1_SX214_AL_.jpg Actress, "The Mummy" Rachel Weisz
http://ia.media-imdb.com/images/M/MV5BMjE0Mjg0NzE2Nl5BMl5BanBnXkFtZTcwMDE1MTkxMw@@._V1_SX214_AL_.jpg Actor, "Jarhead" Peter Sarsgaard
http://ia.media-imdb.com/images/M/MV5BMTMyOTYzODQ5MF5BMl5BanBnXkFtZTcwMjE3MDgzMQ@@._V1_SX214_AL_.jpg Actress, "Blades of Glory" Jenna Fischer
http://ia.media-imdb.com/images/M/MV5BMzE2OTAwNzM0Ml5BMl5BanBnXkFtZTcwNzE1MDg0Mw@@._V1_SX214_AL_.jpg Actress, "Tangled" Donna Murphy
http://ia.media-imdb.com/images/M/MV5BMTI0OTMzMzE0N15BMl5BanBnXkFtZTcwMjI1MzYyMQ@@._V1_SX214_AL_.jpg Actor, "How the Grinch Stole Christmas" T.J. Thyne
http://ia.media-imdb.com/images/M/MV5BNzczODkyNzY4OV5BMl5BanBnXkFtZTcwNTU0NjQzMQ@@._V1_SX214_AL_.jpg Actor, "Home Alone" John Heard
http://ia.media-imdb.com/images/M/MV5BMTg4MjU2MzA2OV5BMl5BanBnXkFtZTgwOTIxMjc4MjE@._V1_SX214_AL_.jpg Actress, "Beerfest" Audrey Marie Anderson
http://ia.media-imdb.com/images/M/MV5BMTQyOTc5NzA0M15BMl5BanBnXkFtZTYwODQ2MjYz._V1_SX214_AL_.jpg Producer, "Kick-Ass" Matthew Vaughn

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用BeautifulSoup抓取特定网站

来自分类Dev

如何使用python和beautifulsoup4循环抓取网站中多个页面的数据

来自分类Dev

使用BeautifulSoup 4.8.2从网站抓取表格

来自分类Dev

使用 BeautifulSoup 从网站抓取数据的问题

来自分类Dev

无法使用beautifulsoup抓取日本网站

来自分类Dev

如何使用BeautifulSoup和Python抓取页面?

来自分类Dev

Web使用BeautifulSoup抓取多个页面

来自分类Dev

使用 BeautifulSoup 在 python 中抓取多个页面

来自分类Dev

使用 BeautifulSoup 从抓取的页面中提取文本

来自分类Dev

使用beautifulsoup抓取动态加载页面

来自分类Dev

网站抓取YouTube页面

来自分类Dev

使用 Scrapy 在 imdb 中抓取每个单独的电影网站

来自分类Dev

使用Selenium和BeautifulSoup输入内容来抓取网站?

来自分类Dev

使用python中的BeautifulSoup从网站抓取报告

来自分类Dev

使用beautifulsoup抓取HTML网站ID的特定部分

来自分类Dev

如何使用Beautifulsoup从网站上抓取产品价格?

来自分类Dev

当我尝试使用BeautifulSoup从网站抓取时缺少文本

来自分类Dev

如何使用BeautifulSoup从eCom网站上抓取<li>?

来自分类Dev

使用python和beautifulsoup抓取多页网站

来自分类Dev

使用beautifulsoup从网站抓取表格,最后出现错误

来自分类Dev

使用python 2.7和beautifulsoup 4进行网站抓取

来自分类Dev

使用 BeautifulSoup 抓取网站:TypeError: 'NoneType' 对象不可调用

来自分类Dev

使用python抓取网站时获取最大页面数

来自分类Dev

如何使用Scrapy抓取网站所有页面上的链接

来自分类Dev

使用Selenium(Python3)抓取网站的多个页面

来自分类Dev

使用python抓取网站时获取最大页面数

来自分类Dev

使用 rvest 抓取网站(更改页面、点击链接)

来自分类Dev

如何使用Python和BeautifulSoup抓取多个Google页面

来自分类Dev

如何使用BeautifulSoup创建循环以从源URL抓取多个页面?

Related 相关文章

  1. 1

    使用BeautifulSoup抓取特定网站

  2. 2

    如何使用python和beautifulsoup4循环抓取网站中多个页面的数据

  3. 3

    使用BeautifulSoup 4.8.2从网站抓取表格

  4. 4

    使用 BeautifulSoup 从网站抓取数据的问题

  5. 5

    无法使用beautifulsoup抓取日本网站

  6. 6

    如何使用BeautifulSoup和Python抓取页面?

  7. 7

    Web使用BeautifulSoup抓取多个页面

  8. 8

    使用 BeautifulSoup 在 python 中抓取多个页面

  9. 9

    使用 BeautifulSoup 从抓取的页面中提取文本

  10. 10

    使用beautifulsoup抓取动态加载页面

  11. 11

    网站抓取YouTube页面

  12. 12

    使用 Scrapy 在 imdb 中抓取每个单独的电影网站

  13. 13

    使用Selenium和BeautifulSoup输入内容来抓取网站?

  14. 14

    使用python中的BeautifulSoup从网站抓取报告

  15. 15

    使用beautifulsoup抓取HTML网站ID的特定部分

  16. 16

    如何使用Beautifulsoup从网站上抓取产品价格?

  17. 17

    当我尝试使用BeautifulSoup从网站抓取时缺少文本

  18. 18

    如何使用BeautifulSoup从eCom网站上抓取<li>?

  19. 19

    使用python和beautifulsoup抓取多页网站

  20. 20

    使用beautifulsoup从网站抓取表格,最后出现错误

  21. 21

    使用python 2.7和beautifulsoup 4进行网站抓取

  22. 22

    使用 BeautifulSoup 抓取网站:TypeError: 'NoneType' 对象不可调用

  23. 23

    使用python抓取网站时获取最大页面数

  24. 24

    如何使用Scrapy抓取网站所有页面上的链接

  25. 25

    使用Selenium(Python3)抓取网站的多个页面

  26. 26

    使用python抓取网站时获取最大页面数

  27. 27

    使用 rvest 抓取网站(更改页面、点击链接)

  28. 28

    如何使用Python和BeautifulSoup抓取多个Google页面

  29. 29

    如何使用BeautifulSoup创建循环以从源URL抓取多个页面?

热门标签

归档