【发布时间】:2018-06-19 12:11:53
【问题描述】:
import requests
from bs4 import BeautifulSoup
#Finds the imdb rating of a given movie or TV series
search_term1="What is the imdb rating of "
search_term2=input("Enter the name of the movie or TV Series : ")
search_term=search_term1+search_term2
response=requests.get("https://www.google.co.in/search?q="+search_term)
soup = BeautifulSoup(response.text, 'html5lib')
match=soup.find('div.slp.f')
#i tried 'div',_class="slp.f"
print(match) #this line is returning none
我正在尝试从谷歌搜索引擎中提取电影的 imdb 评级。每次它都没有返回,尽管 id 是正确的。
【问题讨论】:
-
这是因为您的脚本会引导您进入验证码页面。尝试使用
print(response.url)进行检查。我猜返回的url和请求的url不一样。 -
此外,您的搜索词应正确编码,我在您的脚本中看不到任何此类尝试。如果您请求的网址尚未重定向,请尝试使用
quote_plus(search_term)和之前的from urllib.parse import quote_plus。
标签: html web-scraping beautifulsoup python-requests web-crawler