python爬取游戏新闻和视频
2021/8/22 20:06:17
本文主要是介绍python爬取游戏新闻和视频,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本人是个爬虫小萌新,看了网上教程学着做了一些,如果有什么问题请大佬们反馈,谢谢。
以下是用lxml来爬取的。
import requests from lxml import etree def getHTMLText(url): kv = { 'cookie': 'ssids=1581214855718752; sfroms=JIAOYIMALL001; historyScanGame=%5B%225667%22%2Cnull%5D; session=1581214855718753-7; showFixGuideDialog=true' , 'user-agent': 'Mozilla/5.0'} r = requests.get(url, headers=kv) r.raise_for_status() r.encoding = 'utf-8' return r.text def shixian(url): htmls = etree.HTML(url) mc = htmls.xpath( '//div[@class="wrap"]/div[@class="mod-con sel-content "]/div[@class="bd"]/ul[@class="list-con specialList"]/li[@name="goodsItem"]/span[@class="name"]/span[@class="is-account"]/a/text()') price = htmls.xpath( '//div[@class="wrap"]/div[@class="mod-con sel-content "]/div[@class="bd"]/ul[@class="list-con specialList"]/li[@name="goodsItem"]/span[@class="price"]') count = 0 tplt = "{:4}\t{:12}\t{:20}" print(tplt.format("序号", "价格", "商品")) for i in range(len(mc)): count = count + 1 print(tplt.format(count, price[i].text, mc[i], chr(12288))) if __name__ == '__main__': url='https://www.fgba.net/forum-53-1.html' lists=[] url=url+'-n'+'1'+'.html' html=getHTMLText(url) shixian(html)
这篇关于python爬取游戏新闻和视频的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程