函数原型:find(str, pos_start, pos_end)
解释:
- str:被查找“字串”
- pos_start:查找的首字母位置(从0开始计数。默认:0)
- pos_end: 查找的末尾位置(默认-1)
返回值:如果查到:返回查找的第一个出现的位置。否则,返回-1。
request = urllib.request.Request(url=url, headers=headers)
feeddata = urllib.request.urlopen(request).read().decode('utf-8')
soup = BeautifulSoup(feeddata, 'html.parser')
content = soup.find_all("div", class_="lvpic pic img left", iid=True, limit=4)
result = []
for i in content:
s = str(i)
l = s.find("iid=")
if l == -1:
continue
r = s.find("\">")
result.append(str(s[l + 5:r]))
print(result)