这是网页上的script 我要获取的是00914这个数字  直接使用正则表达式即可

运行结果:

源码:

import re
from bs4 import BeautifulSoup
from urllib.request import urlopen
url = "你要解析的网页URL"
html = urlopen(url).read()
soup = BeautifulSoup(html,"html.parser")
titles = soup.select("body script") # CSS 选择器
i = 1
for title in titles:
if i == 3:
#print(title.get_text())# 标签体、标签属性
str=title.get_text()
break
if i == 2:
i = 3
if i == 1:
i = 2 print(str)
str1 = "\"\"\""+"<script>"+str+"</script>"+"\"\"\""
soup = BeautifulSoup(str1, "html.parser")
pattern = re.compile(r"var _url = '(.*?)';$", re.MULTILINE | re.DOTALL)
script = soup.find("script", text=pattern)
#print (pattern.search(script.text).string)
s = pattern.search(script.text).string
print (s.split('\'')[11])

  

最新文章

  1. linux 驱动学习笔记05--文件系统与设备文件系统
  2. Nexus Repository Manager 3.0 发布
  3. Java mysql 日期相关
  4. Mac开发环境搭建
  5. C++语法疑点
  6. Java实现Qt的SIGNAL-SLOT机制
  7. java Socket使用详细解释
  8. Spring五个事务隔离级别和七个事务传播行为
  9. python基础之字典、赋值补充
  10. python(字符串操作)
  11. 使用 jquery.wordexport.js导出的Word排版
  12. HTML&amp;javaSkcript&amp;CSS&amp;jQuery&amp;ajax(11)
  13. iOS 拨打电话三种方式
  14. 详解php中serialize()和unserialize()函数
  15. dedecms前端无法调用自定义变量怎么解决
  16. 【sping揭秘】2、关于spring配置文件
  17. Android设计 - 图标设计概述(Iconography)
  18. Android SDK无法更新的问题解决办法
  19. IOS-网络(网页开发-UIWebView,HTML,CSS,JavaScript,OC和JS代码互调)
  20. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 7 Regularization 正则化

热门文章

  1. 腾讯云短信服务+Node.js给手机发送验证码
  2. CF1195E OpenStreetMap
  3. 【2019.8.6 慈溪模拟赛 T3】集合(set)(线段树上DP)
  4. bootstrap-editable 中关于onEditableSave 回调
  5. maven pom项目的dependencies转gradle格式
  6. 匿名函数和for_each用法
  7. Appium swipe实现屏幕滑动
  8. git 给分支添加描述 管理分支实用方法
  9. 读取指定页面中的超链接-Python 3.7
  10. Unsupervised Attention-guided Image-to-Image Translation