beautifulsoup

Trying to get encoding from a webpage Python and BeautifulSoup

谁都会走 提交于 2019-12-22 00:46:44
问题 Im trying to retrieve the charset from a webpage(this will change all the time). At the moment Im using beautifulSoup to parse the page and then extract the charset from the header. This was working fine until I ran into a site that had..... <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> My code up until now and which was working with other pages is: def get_encoding(soup): encod = soup.meta.get('charset') if encod == None: encod = soup.meta.get('content-type') if encod =

Extracting value in Beautifulsoup

混江龙づ霸主 提交于 2019-12-22 00:44:10
问题 I have the following code: f = open(path, 'r') html = f.read() # no parameters => reads to eof and returns string soup = BeautifulSoup(html) schoolname = soup.findAll(attrs={'id':'ctl00_ContentPlaceHolder1_SchoolProfileUserControl_SchoolHeaderLabel'}) print schoolname which gives: [<span id="ctl00_ContentPlaceHolder1_SchoolProfileUserControl_SchoolHeaderLabel">A B Paterson College, Arundel, QLD</span>] when I try and access the value (i.e. 'A B Paterson College, Arundel, QLD) by using

Setting a plain checkbox with robobrowser

空扰寡人 提交于 2019-12-22 00:27:27
问题 I am struggling to check a simple checkbox with robobrowser to discard all messages in mailman. form['discardalldefersp'].options returns ['0'] , neither form['discardalldefersp'].value= True nor form['discardalldefersp'].value = '1' delivers a result. I only get 'ValueError: Option 1 not found in field ' How can I set the checkbox? My code for the whole thing is as following: import robobrowser pw = '<password>' browser = RoboBrowser(history=True) browser.open('<mailmanlist>') form = browser

Beautifulsoup lost nodes

僤鯓⒐⒋嵵緔 提交于 2019-12-22 00:15:01
问题 I am using Python and Beautifulsoup to parse HTML-Data and get p-tags out of RSS-Feeds. However, some urls cause problems because the parsed soup-object does not include all nodes of the document. For example I tried to parse http://feeds.chicagotribune.com/~r/ChicagoBreakingNews/~3/T2Zg3dk4L88/story01.htm But after comparing the parsed object with the pages source code, I noticed that all nodes after ul class="nextgen-left" are missing. Here is how I parse the Documents: from bs4 import

Remove all <a> tags

大兔子大兔子 提交于 2019-12-21 22:38:25
问题 I scraped one container which includes urls for example: <a href="url">text</a> I need all to be removed and only the text remain... import urllib2, sys from bs4 import BeautifulSoup site = "http://mysite.com" page = urllib2.urlopen(site) soup = BeautifulSoup(page) Is it possible? 回答1: soup = BeautifulSoup(page) anchors = soup.findAll('a') for anchor in anchors: anchor.replaceWithChildren() 回答2: You can do this with Bleach PyPi - Bleach >>> import bleach >>> bleach.clean('an <script>evil()<

Importing and Using BeautifulSoup for Web App

不羁的心 提交于 2019-12-21 22:35:20
问题 I am currently trying to use BeautifulSoup for a Web App and I have installed the beautifulsoup4 egg in a local dir with easy_install --install-dir=PATH_TO_DIR beautifulsoup4 , but when I run my app I'm getting the current error that I don't know what to do about: Traceback (most recent call last): from bs4 import BeautifulSoup File "/home/ryanefoley/py_libs/beautifulsoup4-4.3.2-py2.6.egg/bs4/__init__.py", line 186 if ((isinstance(markup, bytes) and not b' ' in markup) ^ SyntaxError: invalid

spaced output beautifulsoup

一笑奈何 提交于 2019-12-21 21:04:07
问题 Im trying to scrap the contents of a website. However in the output im getting unwanted spaces and hence im not able to interpret this output. Im using a simple code : import urllib2 from bs4 import BeautifulSoup html= 'http://idlebrain.com/movie/archive/index.html' soup = BeautifulSoup(urllib2.urlopen(html).read()) print(soup.prettify(formatter=None)) OUTPUT::(output is very large so a small part of it in order to understand what problem im facing) <html><head><title>Telugu cinema reviews by

Python学习日记5|BeautifulSoup中find和find_all的用法

点点圈 提交于 2019-12-21 15:19:12
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Python学习日记5|BeautifulSoup中find和find_all的用法 是蓝先生 关注 2016.04.20 11:26* 字数 930 阅读 37205评论 11喜欢 10 今天是4.20号。 前天晚上看到蒋方舟的一句话: 不要左顾右盼。慢慢积累,慢慢写吧。毕竟除了这样单调的努力,我什么也做不了。 而现在的自己就是个十足的壁花少年。 在进入正题前先说一下每次完成代码后,可以用ctrl+alt+l对代码进行自动格式规范化。 在爬取网页中有用的信息时,通常是对存在于网页中的文本或各种不同标签的属性值进行查找,Beautiful Soup中内置了一些查找方式,最常用的是find()和find_all()函数。[文献引自 http://blog.csdn.net/abclixu123/article/details/38502993 ]。 同时通过soup.find_all()得到的所有符合条件的结果和soup.select()一样都是列表list,而soup.find()只返回第一个符合条件的结果,所以soup.find()后面可以直接接.text或者get_text()来获得标签中的文本。 一、find()用法 find(name,attrs,recursive,text,**wargs)

Flurry Login Requests.Session() Python 3

自闭症网瘾萝莉.ら 提交于 2019-12-21 14:54:21
问题 So I had this question answered before here. However, something on the Flurry website has changed and the answer no longer works. from bs4 import BeautifulSoup import requests loginurl = "https://dev.flurry.com/secure/loginAction.do" csvurl = "https://dev.flurry.com/eventdata/.../..." #URL to get CSV data = {'loginEmail': 'user', 'loginPassword': 'pass'} with requests.Session() as session: session.headers.update({ "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like

Extract string from tag with BeautifulSoup

点点圈 提交于 2019-12-21 12:36:41
问题 I am trying to extract from below table. I cut it after second , 6 more to follow. All in all eight strings to be extracted and I need from below example value 61.5, value 56.43 etc. Below code snipplet gives me only first value(61.5). How can I grab the remaining values? soup.find("div", {"class":"value"}).text <td class="flow"> <div class="heading" style="min-height: 63px;">Dornum</div> <div class="data"><div class="value">61.5</div> MSm<sup>3</sup>/d</div> </td> <td class="flow"> <div