<a href="http://goldfilmesonline.com/inferno-dublado-online/" class="tip_trigger" style="float: left;">
<span class="tip" style="left: 597px; width: 400px; margin-top: 3px; display: none;"><div class="bg-tooltips"><img width="100%" src="https://image.tmdb.org/t/p/w780/anmLLbDx9d98NMZRyVUtxwJR6ab.jpg"></div></span>
<span class="tip" style="left: 597px; width: 400px; margin-top: 3px; display: none;">
<div style="height:210px;"
<div class="tooltips-info-box-bg-topo">
<div class="tooltips-info-box-title">Inferno Dublado Online<br><span>Inferno ( 2016 ) </span> </div>
<div class="tooltips-info-box-imdbRating">6.4</div>
</div><!-- tooltips-info-box-bg-topo -->
<div class="tooltips-info-box-bg-meio">
<div class="tooltips-info-box-sinopse"><b>Sinopse: </b>O renomado professor de simbologia de Harvard, Robert Langdon (Tom Hanks) visita a Itália e se envolve em mais uma aventura envolvendo símbolos ocultos e corporações secretas. Ele se vê em uma jornada em que procura desvendar os mistérios do clássico da literatura “A Divina Comédia”, de Dante Alighieri.</div>
</div><!-- tooltips-info-box-bg-meio -->
<div class="tooltips-info-box-bg-rodape">
<div class="tooltips-info-box-genero"><b>Genero:</b> Ação, Aventura, Dublado, Lançamentos, Policial, </div>
</div><!-- tooltips-info-box-bg-rodape -->
</div></span>
<div class="box-filme">
<div class="capa-miniatura"><div class="capa-miniatura-hover"></div>
<img width="185" height="272" src="http://goldfilmesonline.com/wp-content/uploads/2016/12/Inferno-Dublado-Online.jpg" class="attachment-inicio-thumbnails size-inicio-thumbnails wp-post-image" alt="inferno-dublado-online" srcset="http://goldfilmesonline.com/wp-content/uploads/2016/12/Inferno-Dublado-Online.jpg 185w, http://goldfilmesonline.com/wp-content/uploads/2016/12/Inferno-Dublado-Online-160x235.jpg 160w" sizes="(max-width: 185px) 100vw, 185px"><div class="quali">HDRip</div>
<div class="dub">Dublado</div>
</div>
</div>
</a>
什么是最好的反击方式(href =,title和src =)
我想使用:requests,beautifulSoup,re
这是网站“http://goldfilmesonline.com/category/lancamentos/”
这就是我想出的:
import urllib2
import urllib
import re
def open(url):
req = urllib2.Request(url)
req.add_header('User-agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0')
response = urllib2.urlopen(req)
link = response.read()
response.close()
return link#.replace('\n', '').replace('\t','').replace('\r','')
url = 'http://goldfilmesonline.com/category/lancamentos/'
content = open(url)
q = re.compile('<img width=".+?" height=".+?" src="(.+?)" class=".+?" alt="(.+?)"').findall(content)
for valor in q:
a = valor[0]
b = valor[1]
x = re.compile('<a href="(.+?)" class=".+?" style=".+?">').findall(content)
for c in x:
print a, b, c
答案 0 :(得分:1)
import urllib2
import urllib
import re
def open(url):
req = urllib2.Request(url)
req.add_header('User-agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0')
response = urllib2.urlopen(req)
link = response.read()
response.close()
return link#.replace('\n', '').replace('\t','').replace('\r','')
url = 'http://goldfilmesonline.com/category/lancamentos/'
content = open(url)
match = re.compile('<a href="(.+?)" class="tip_trigger" style="float: left;">').findall(content)
match2 = re.compile('<span>(.+?) </span>').findall(content)
match3 = re.compile('<img width=".+?" height=".+?" src="(.+?)" class="attachment-inicio-thumbnails size-inicio-thumbnails wp-post-image"').findall(content)
for a in match:
url = a
for b in match2:
name = b
for c in match3:
image = c
print (url, name, image)
答案 1 :(得分:1)
再次播放我的代码我发现甚至更好的方式匹配,match2和match3我把所有它放在一个匹配,所以它保持这样
import urllib2
import urllib
import re
def open(url):
req = urllib2.Request(url)
req.add_header('User-agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0')
response = urllib2.urlopen(req)
link = response.read()
response.close()
return link#.replace('\n', '').replace('\t','').replace('\r','')
url = 'http://goldfilmesonline.com/category/lancamentos/'
content = open(url)
match = re.compile('<a href="(.+?)">.+?<span>(.+?) </span>.+?<img width=".+?" height=".+?" src="(.+?)" class="attachment-inicio-thumbnails size-inicio-thumbnails wp-post-image"',re.DOTALL).findall(content)
for url, name , image in match:
print url, name, image
答案 2 :(得分:1)
import requests
from bs4 import BeautifulSoup
r = requests.get('http://goldfilmesonline.com/category/lancamentos/')
soup = BeautifulSoup(r.text, 'lxml')
box = soup.find_all(class_='tip_trigger')
for i in box:
href = i['href']
title = href.split('/')[-2]
src = i.find('img')['src']
print(href, title, src, sep='\n')
print('-'*50)
出:
http://goldfilmesonline.com/o-contador-legendado-online-2/
o-contador-legendado-online-2
https://image.tmdb.org/t/p/w780/i9flZtw3BwukADQpu5PlrkwPYSY.jpg
--------------------------------------------------
http://goldfilmesonline.com/cegonhas-a-historia-que-nao-te-contaram-legendado-online/
cegonhas-a-historia-que-nao-te-contaram-legendado-online
https://image.tmdb.org/t/p/w780/z0EuTtBwp0ZxUVoFZAh3oi5CflZ.jpg
--------------------------------------------------
http://goldfilmesonline.com/sully-o-heroi-do-rio-hudson-legendado-online/
sully-o-heroi-do-rio-hudson-legendado-online
https://image.tmdb.org/t/p/w780/vC9H1ZVdXi1KjH4aPfGB54mvDNh.jpg
--------------------------------------------------
http://goldfilmesonline.com/morgan-legendado-online/
morgan-legendado-online
https://image.tmdb.org/t/p/w780/g3XhTkjUxLbzVVa63vuopSNNZE8.jpg
--------------------------------------------------
http://goldfilmesonline.com/inferno-dublado-online/
inferno-dublado-online
https://image.tmdb.org/t/p/w780/anmLLbDx9d98NMZRyVUtxwJR6ab.jpg
--------------------------------------------------
http://goldfilmesonline.com/florence-quem-e-essa-mulher-dublado-online/
florence-quem-e-essa-mulher-dublado-online
https://image.tmdb.org/t/p/w780/3H84jPFtoHEEgy1XJOVTXJBjYk8.jpg
--------------------------------------------------
http://goldfilmesonline.com/i-am-bolt-legendado-online/
i-am-bolt-legendado-online
https://image.tmdb.org/t/p/w780/etzrwJB7502UooJ0KRYkwt5bFR5.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-lar-das-criancas-peculiares-legendado-online/
o-lar-das-criancas-peculiares-legendado-online
https://image.tmdb.org/t/p/w780/qXQinDhDZkTiqEGLnav0h1YSUu8.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-dragao-do-natal-dublado-online/
o-dragao-do-natal-dublado-online
https://image.tmdb.org/t/p/w780/iKpfJBA5srFMeVTqxRGhMepTh74.jpg
--------------------------------------------------
http://goldfilmesonline.com/operacao-chromite-dublado-online/
operacao-chromite-dublado-online
https://image.tmdb.org/t/p/w780/pAkzDf8daAGFeaHioAJgyHCvNFK.jpg
--------------------------------------------------
http://goldfilmesonline.com/animais-fantasticos-e-onde-habitam-dublado-online-2/
animais-fantasticos-e-onde-habitam-dublado-online-2
https://image.tmdb.org/t/p/w780/6I2tPx6KIiBB4TWFiWwNUzrbxUn.jpg
--------------------------------------------------
http://goldfilmesonline.com/esquadrao-suicida-dublado-online/
esquadrao-suicida-dublado-online
https://image.tmdb.org/t/p/w780/ndlQ2Cuc3cjTL7lTynw6I4boP4S.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-homem-nas-trevas-dublado-online/
o-homem-nas-trevas-dublado-online
https://image.tmdb.org/t/p/w780/bCThHXQ3aLLDU3KFST0rC8mTan5.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-homem-que-viu-o-infinito-dublado-online/
o-homem-que-viu-o-infinito-dublado-online
https://image.tmdb.org/t/p/w780/A5ACRzx0eNuKI8qISuOBFWICFE4.jpg
--------------------------------------------------
http://goldfilmesonline.com/snowden-heroi-ou-traidor-legendado-online/
snowden-heroi-ou-traidor-legendado-online
https://image.tmdb.org/t/p/w780/qzGFm7uF1HExPUAcAPwC3Hzk5WR.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-tunel-legendado-online/
o-tunel-legendado-online
https://image.tmdb.org/t/p/w780/zA0r2Zn4atpGSdciv96V27x4Qvl.jpg
--------------------------------------------------
http://goldfilmesonline.com/trolls-legendado-online/
trolls-legendado-online
https://image.tmdb.org/t/p/w780/wc1JxADaBLuWhySkaawCBTpixCo.jpg
--------------------------------------------------
http://goldfilmesonline.com/ben-hur-2016-dublado-online/
ben-hur-2016-dublado-online
https://image.tmdb.org/t/p/w780/A4xbEpe9LevQCdvaNC0z6r8AfYk.jpg
--------------------------------------------------
http://goldfilmesonline.com/voo-de-emergencia-dublado-online/
voo-de-emergencia-dublado-online
https://image.tmdb.org/t/p/w780/nXGKybgpoa14hTnpq4KR24ce8dP.jpg
--------------------------------------------------
http://goldfilmesonline.com/a-chegada-dublado-online/
a-chegada-dublado-online
https://image.tmdb.org/t/p/w780/wFFlaVHmQG4U43m0l3eQqHZluvn.jpg
--------------------------------------------------
http://goldfilmesonline.com/punhos-de-aco-legendado-online/
punhos-de-aco-legendado-online
https://image.tmdb.org/t/p/w780/wweNPWBO4S2isIU7kgu1j4mmyMB.jpg
--------------------------------------------------
http://goldfilmesonline.com/arrume-um-emprego-dublado-online/
arrume-um-emprego-dublado-online
https://image.tmdb.org/t/p/w780/gwDnVDS4ltWRcSdKnmcTfrfLopU.jpg
--------------------------------------------------
http://goldfilmesonline.com/heranca-de-sangue-dublado-online/
heranca-de-sangue-dublado-online
https://image.tmdb.org/t/p/w780/i5L4oUX9gaKAPHIoAOFGVnY2tkq.jpg
--------------------------------------------------
http://goldfilmesonline.com/um-dia-perfeito-dublado-online/
um-dia-perfeito-dublado-online
http://filmesegames.com.br/wp-content/uploads/2016/02/perfectday-xlarge.jpg
--------------------------------------------------
http://goldfilmesonline.com/aquarius-nacional-online/
aquarius-nacional-online
https://image.tmdb.org/t/p/w780/ur6BtlfIB1ayG2qeQZZNVt2hq5G.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-roubo-da-taca-nacional-online/
o-roubo-da-taca-nacional-online
http://www.movieaholic.com.br/wp-content/uploads/2016/09/maxresdefault-1.jpg
--------------------------------------------------
http://goldfilmesonline.com/jack-reacher-sem-retorno-dublado-online/
jack-reacher-sem-retorno-dublado-online
https://image.tmdb.org/t/p/w780/4ynQYtSEuU5hyipcGkfD6ncwtwz.jpg
--------------------------------------------------
http://goldfilmesonline.com/absolutely-fabulous-o-filme-dublado-online/
absolutely-fabulous-o-filme-dublado-online
https://image.tmdb.org/t/p/w780/xykD55jk7NQmVG8iQWTsHyMKJL5.jpg
--------------------------------------------------
http://goldfilmesonline.com/animais-fantasticos-e-onde-habitam-dublado-online/
animais-fantasticos-e-onde-habitam-dublado-online
https://image.tmdb.org/t/p/w780/6I2tPx6KIiBB4TWFiWwNUzrbxUn.jpg
--------------------------------------------------
http://goldfilmesonline.com/come-and-find-me-legendado-online/
come-and-find-me-legendado-online
https://image.tmdb.org/t/p/w780/saS0N6lE8ZyKH46dlqAsPqDWuk0.jpg
--------------------------------------------------
http://goldfilmesonline.com/os-dois-lados-da-justica-legendado-online/
os-dois-lados-da-justica-legendado-online
https://image.tmdb.org/t/p/w780/49xLFrqrU1KIoQpUlixlOhiDbU6.jpg
--------------------------------------------------
http://goldfilmesonline.com/uma-noite-com-a-familia-blacks-dublado-online/
uma-noite-com-a-familia-blacks-dublado-online
https://image.tmdb.org/t/p/w780/d8TOaHhU8hwKI5Q2yHjzVvf26GX.jpg
--------------------------------------------------
http://goldfilmesonline.com/the-remains-legendado-online-2/
the-remains-legendado-online-2
https://image.tmdb.org/t/p/w780/rsbMpwxTJaRPchPFiM1syW2otcJ.jpg
--------------------------------------------------
http://goldfilmesonline.com/the-neighbor-legendado-online-2/
the-neighbor-legendado-online-2
https://image.tmdb.org/t/p/w780/qKbrLPdeeXFUUtOfbOxsql4V2wo.jpg
--------------------------------------------------
http://goldfilmesonline.com/goldstone-legendado-online/
goldstone-legendado-online
https://image.tmdb.org/t/p/w780/uJnmwWiGvcdX9qDSVAlJVEA9x1j.jpg
--------------------------------------------------
http://goldfilmesonline.com/perfeita-e-a-mae-dublado-online/
perfeita-e-a-mae-dublado-online
https://image.tmdb.org/t/p/w780/elPpPBuYB2Zn5wFwz2FSlJlKUjp.jpg
--------------------------------------------------
http://goldfilmesonline.com/aguas-rasas-dublado-online-2/
aguas-rasas-dublado-online-2
https://image.tmdb.org/t/p/w780/lEkHdk4g0nAKtMcHBtSmC1ON3O1.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-sono-da-morte-dublado-online/
o-sono-da-morte-dublado-online
https://image.tmdb.org/t/p/w780/17leifwr5lVoob1mFPK6hB79VD3.jpg
--------------------------------------------------
http://goldfilmesonline.com/o-contador-legendado-online/
o-contador-legendado-online
https://image.tmdb.org/t/p/w780/i9flZtw3BwukADQpu5PlrkwPYSY.jpg
--------------------------------------------------
http://goldfilmesonline.com/fora-do-rumo-dublado-online/
fora-do-rumo-dublado-online
https://image.tmdb.org/t/p/w780/1dQvBH9aZwFjXq492yKoLKJZkoy.jpg
--------------------------------------------------
http://goldfilmesonline.com/conexao-escobar-dublado-online/
conexao-escobar-dublado-online
https://image.tmdb.org/t/p/w780/ng15G1WxNWrJoc6eG9LQV3VGSn4.jpg
--------------------------------------------------
http://goldfilmesonline.com/jason-bourne-dublado-online-2/
jason-bourne-dublado-online-2
https://image.tmdb.org/t/p/w780/AoT2YrJUJlg5vKE3iMOLvHlTd3m.jpg
--------------------------------------------------
答案 3 :(得分:0)
我通常使用lxml来执行此类任务。另请检查scrapy
库。
使用lxml获取所有链接href
s:
from lxml import html
import requests
req = requests.get('http://goldfilmesonline.com/category/lancamentos/')
htmlTree = html.fromstring(req.content)
links = htmlTree.xpath("//a")
hrefs = [link.attrib['href'] for link in links]