|
发表于 2019-10-4 11:23:07
|
显示全部楼层
没调用方法,应该这样:
- import requests
- import bs4
- def url_open(url):
- headers = {"user-agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3722.400 QQBrowser/10.5.3751.400"}
- res = requests.get(url,headers=headers)
- return res
- def get_girl_url(res):
- soup = bs4.BeautifulSoup(res.text,"html.parser")
- img_url = soup.find(class_='main-image').find('img').get('src')
- print(img_url)
- def main():
- url = "https://www.mzitu.com/205572"
- res = url_open(url)
- get_girl_url(res)
- if __name__ == "__main__":
- main()
复制代码 |
|