我试图用下面的代码和平废弃谷歌图片页面。在# -*- coding: utf-8 -*-
import urllib2
from bs4 import BeautifulSoup
site= "https://www.google.co.in/search?q=batman+wallpaper+hd&source=lnms&tbm=isch"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
req = urllib2.Request(site,headers=hdr)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page, 'html.parser')
for child in soup.find("div", {"data-ri":"16"}).children:
print child
得到这个输出
^{pr2}$
我想读取“ou”标签的值,这是链接到墙纸的链接,有人能帮我解析那个链接中的变量。python初学者。提前谢谢。在