从python的网页中的id获取单词

时间:2016-01-30 15:10:32

标签: python beautifulsoup urllib

我希望python从网站上读取特定的单词, 我在urllib和bs4中搜索过,但我没有找到任何可以做到这一点的例子

我想要的例子:

在此页https://www.google.com.eg/search?q=weather%20in%20egypt&gws_rd=ssl

我想让python阅读:

>>>id = wob_tm
>>>print 'weather is ' + id 
weather is 16

有可能吗?

1 个答案:

答案 0 :(得分:0)

如果您需要此信息,您应该使用API​​。但是如果您只想从页面获取一个数据,并且您已经在变量中使用了HTML响应,那么使用简单的正则表达式(而不是解析整个页面)没有错:

byte[] bytes = Jsoup.connect(imgUrl).ignoreContentType(true).execute().bodyAsBytes();

该值将在比赛的第1组中找到 Demo here