Beautiful Soup and re
使用urllib.request模块读取HTML文件
import urllib.request
from bs4 import BeautifulSoup
url="网页地址"
response=urllib.request.urlopen(url)
html=response.read()
soup=BeautifulSoup(html,"html.parser")
BeautifulSoup(html,"html.parser")是对数据的提取和对参数的解析器(parser)
使用find_all(href=re.compile("view"))可找到相关的链接
re:
re可以找到相关的匹配位置:
>>> import re
>>> re.search(r'hao.360.cn','https://hao.360.cn/?src=lm&ls=n1bcffc0294')
<re.Match object; span=(8, 18), match='hao.360.cn'>
>>>
>用pythonshell完成的一个操作,查到了正则表达式模块第一次的出现,但具体也不是很懂
所以一开始代码整合如下
import urllib.request
import parser(#对数据解析)
import re
from bs4 import BeautifulSoup