|  | 
 
 
 楼主|
发表于 2019-10-18 12:57:31
|
显示全部楼层 
| import requests
 import bs4
 
 def get_url(url):
 headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}
 
 res = requests.get(url,headers=headers)
 return res
 
 def main():
 url = 'https://www.opendota.com/heroes/1'
 hero_list = []
 html = get_url(url)
 soup = bs4.BeautifulSoup(html.text,'html.parser')
 targets = soup.find_all("div", class_="sc-kZmsYB WTZVj")
 for each in targets:
 print(each)
 
 if __name__ == '__main__':
 main()
 | 
 |