python爬虫简单实例

608次阅读
没有评论
python爬虫简单实例

【实例简介】

【实例截图】

【核心代码】

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免费测试

相关文章:

版权声明:Python教程2022-10-28发表,共计592字。
新手QQ群:570568346,欢迎进群讨论 Python51学习