我是Python的新手,并试图在Python中创建一个脚本,该脚本会刮擦一个网站并在几个链接中返回文本。出于某种原因,我不明白为什么这不起作用,并想知道为什么。我的正则表达式是:正则表达式在Python中没有得到我想要的结果
> regex = re.compile(r'<a target="_blank" title=".+" href=".+.pdf">(.+)</a>')
全码:
import requests, re
response = requests.get('websithere')
websiteDate = response.text
regex = re.compile(r'<a target="_blank" title=".+" href=".+.pdf">(.+)</a>')
mo = regex.findall(websiteDate)
print(mo)
我把(+)组中认为它会发现在那里列出的任何文字。该3个链接它通过扫描为:
> <a target="_blank" title="Farm Business & Production Management
> Instructor" href="/uploadedpdfs/job-opportunities/Farm Business
> Production Mgt Instructor 8-17.pdf">Farm Business & Production
> Management Instructor</a>
>
> <a target="_blank" title="Paramedic Tech Adjunct Instructor Aide"
> href="/uploadedpdfs/job-opportunities/Paramedic Adjunct Instructor
> Aide.pdf">Paramedic Tech Adjunct Instructor Aide</a>
>
> <a target="_blank" title="Technology Support Specialist"
> href="/uploadedpdfs/job-opportunities/Technology Support
> Specialist.pdf">Technology Support Specialist</a>
而不是我的结果只返回: “技术支持专家”
什么我错在这里做什么?我只是试图返回标签内的文字。我尝试了一下,并且无法使其工作。任何帮助,将不胜感激。
谢谢!
您为执行文章中显示的输出而执行哪条语句?请粘贴所有相关的代码。作为一个附注,不要使用REGEX来分析HTML。 https://stackoverflow.com/questions/6751105/why-its-not-possible-to-use-regex-to-parse-html-xml-a-formal-explanation-in-la。使用BeautifulSoup。 – DyZ
不要使用正则表达式来解析html。 –