擅长:python、mysql、java
<p>这个怎么样:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
def infopelicula():
my_url = 'http://www.imdb.com/find?ref_=nv_sr_fn&q="Harry Potter Chamber"&s=tt'
soup = BeautifulSoup(requests.get(my_url).text, 'lxml')
for name in soup.find_all("td",class_="result_text"):
title = name.find_all("a",text=True)[0]
print (title.text)
infopelicula()
</code></pre>
<p>部分输出:</p>
^{pr2}$
<p>仅第一个标题:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
def infopelicula():
my_url = 'http://www.imdb.com/find?ref_=nv_sr_fn&q="Harry Potter Chamber"&s=tt'
soup = BeautifulSoup(requests.get(my_url).text, 'lxml')
for name in soup.find_all("td",class_="result_text")[:1]:
title = name.find_all("a",text=True)[0]
print (title.text)
infopelicula()
</code></pre>
<p>输出:</p>
<pre><code>Harry Potter and the Chamber of Secrets
</code></pre>