[英]Get word from an id in a web page in python
i want python to read a specific word from a website, i searched in urllib and bs4 but i didn't find any example for something that can do this 我想让python从网站上读取一个特定的单词,我在urllib和bs4中进行了搜索,但是我没有找到可以做到这一点的任何示例
example for what i want: 我想要的例子:
on this page https://www.google.com.eg/search?q=weather%20in%20egypt&gws_rd=ssl 在此页面上https://www.google.com.eg/search?q=weather%20in%20egypt&gws_rd=ssl
i want python to read: 我希望python读取:
>>>id = wob_tm
>>>print 'weather is ' + id
weather is 16
is it possible ? 可能吗 ?
You should really be using an API if you want this information. 如果您需要此信息,则应该使用API。 But if you just want one piece of data from the page, and you already have the HTML response in a variable, nothing wrong with using a simple regex (rather than parsing the whole page):
但是,如果您只想从页面中获取一条数据,并且已经在一个变量中包含了HTML响应,那么使用简单的正则表达式(而不是解析整个页面)就没错:
id="wob_tm"[^>]*>([^<]+)
The value will be found in group 1 of the match. 该值将在匹配的第1组中找到。
Demo here . 演示在这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.