【实例简介】
【实例截图】
【核心代码】
from lxml import etree
import requests
def handle_request(url):
heades = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134’,
}
response = requests.get(url=url,headers = heades).text
return response
def main():
url = ‘https://voice.hupu.com/nba’
content = handle_request(url)
news = etree.HTML(content)
news_content = news.xpath(r’//div[@class=”news-list”]/ul/li/div/h4/a/text()’)
news_url = news.xpath(r’//div[@class=”news-list”]/ul/li/div/h4/a/@href’)
for new in zip(news_content ,news_url):
print(new)
if __name__ == ‘__main__’:
main()
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试