使用BS4,Python和Selenium后解析文本(Parse the text after using BS4, Python and Selenium)

使用我的scrape脚本后:

from selenium import webdriver
from bs4 import BeautifulSoup
import csv

browser = webdriver.Firefox()
browser.get('http://dyn.com/about/events/')
html = browser.page_source
soup = BeautifulSoup(html)
titles = [tag.text for tag in soup.find_all('p','pubdate')]

我得到的结果如下:

[u'\ n \ n \ t \ t \ t \ BWEBINAR:如何扩大您的全球覆盖范围到中国\ xa0 \ n \ t \ t \ t \ n \ t \ t \ t设置22,2014 \ t \ t \ t \ nspeak \ n',u'\ n \ n \ t \ t \ t LAUNCH Scale \ u2013旧金山,CA \ xa0 \ n \ t \ t \ t \ n \ t \ t \ t \ tOct 23 - 24,2014 \ t \ t \ t \ nattend \ n',u'\ n \ n \ t \ t \ tAcquia参与用户会议\ u2013 Boston,MA \ xa0 \ n \ t \ t \ t \ n \ t \ t \ t \ t 3 - 5 ,2014 \ t \ t \ t \ nexhibitattend \ n',u'\ n \ n \ t \ t \ t \ tCloud Expo \ u2013圣克拉拉,加利福尼亚\ xa0 \ n \ t \ t \ t \ n \ t \ t \ tNov 4 - 6,2014 \ t \ t \ t \ nexhibit \ n',u'\ n \ n \ t \ t \ t \ 2014年全球运营商奖项\ u2013阿姆斯特丹\ xa0 \ n \ t \ t \ t \ n \ n \ t \ t \ tNov 4,2014 \ t \ t \ t \ n \ n',u'\ n \ n \ t \ t \ t \ t \ twit \ Summit \ u2013都柏林,爱尔兰\ xa0 \ n \ t \ t \ t \ n \ t \ t \ t \ tNov 4 - 6,2014 \ t \ t \ t \ n \ n \ n \ n',u'\ n \ n \ t \ t \ t \ t \ tVelocity Europe \ u2013巴塞罗那,西班牙\ xa0 \ n \ t \ t \ t \ n \ t \ t \ tNov 17 - 19,2014 \ t \ t \ t \ nexhibit \ n',u'\ n \ n \ t \ t \ tNH / VT第一届乐高联赛冠军赛\ xa0 \ n \ t \ t \ t \ n \ t \ t \ tDec 6,2014 \ t \ t \ t \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n“>

我是python的新手,所以你能建议我如何从这个结果中获取事件名称,日期,事件类型?

谢谢!


after using my scrape script:

from selenium import webdriver
from bs4 import BeautifulSoup
import csv

browser = webdriver.Firefox()
browser.get('http://dyn.com/about/events/')
html = browser.page_source
soup = BeautifulSoup(html)
titles = [tag.text for tag in soup.find_all('p','pubdate')]

I have got the result that looks like:

[u'\n\n\t\t\tWEBINAR: How To Expand Your Global Reach To China\xa0\n\t\t\t\n\t\t\tOct 22, 2014\t\t\t\nspeak \n', u'\n\n\t\t\tLAUNCH Scale \u2013 San Francisco, CA\xa0\n\t\t\t\n\t\t\tOct 23 - 24, 2014\t\t\t\nattend \n', u'\n\n\t\t\tAcquia Engage User Conference \u2013 Boston, MA\xa0\n\t\t\t\n\t\t\tNov 3 - 5, 2014\t\t\t\nexhibitattend \n', u'\n\n\t\t\tCloud Expo \u2013 Santa Clara, CA\xa0\n\t\t\t\n\t\t\tNov 4 - 6, 2014\t\t\t\nexhibit \n', u'\n\n\t\t\tThe Global Carrier Awards 2014 \u2013 Amsterdam\xa0\n\t\t\t\n\t\t\tNov 4, 2014\t\t\t\n\n', u'\n\n\t\t\tWeb Summit \u2013 Dublin, Ireland\xa0\n\t\t\t\n\t\t\tNov 4 - 6, 2014\t\t\t\nspeak \n', u'\n\n\t\t\tVelocity Europe \u2013 Barcelona, Spain\xa0\n\t\t\t\n\t\t\tNov 17 - 19, 2014\t\t\t\nexhibit \n', u'\n\n\t\t\tNH/VT FIRST LEGO League Championship Event\xa0\n\t\t\t\n\t\t\tDec 6, 2014\t\t\t\nspeak \n']

I am new to python, so could you suggest how can I get Event Name, Date, Event Type from this result?

Thanks!


原文:https://stackoverflow.com/questions/26484951
2022-11-26 07:11

满意答案

您应该使用外部联接。

select
    A.ID,
    A.DataA1,
    A.DataA2,
    B.A_ID,
    B.DataB1,
    B.DataB2,
    C.A_ID,
    C.DataC1,
    C.DataC2
from A 
left join B
on A.ID = B.A_ID
left join C
on A.ID = C.A_ID

有关SQL连接的详细解释, 请访问http//www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html


You should use an outer join.

select
    A.ID,
    A.DataA1,
    A.DataA2,
    B.A_ID,
    B.DataB1,
    B.DataB2,
    C.A_ID,
    C.DataC1,
    C.DataC2
from A 
left join B
on A.ID = B.A_ID
left join C
on A.ID = C.A_ID

For a good explanation of SQL joins checkout: http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

相关问答

更多

为什么此查询仅返回非空子表的结果?(Why does this query only return results with non-empty child tables?)

当child2没有行时,由于与child2表的内部联接,查询不返回任何行。 如果你内部连接到没有行的表,你将永远不会得到任何结果 - 如果你想在child2为空时得到结果,你必须外连接到child2。 当child2确实有一行时,查询返回结果的原因是因为where子句: WHERE child1.name = 'child1' OR child2.name = 'DOES NOT EXIST'; 内部连接表示child2中必须有匹配ID的内容,但where子句中包含OR,因此只能因为ch...

SQL用于查询具有两个子表的父表中的行,如果不存在子行,则使用空值(SQL to query rows from parent tables with two child tables, with blank values if no child row exists)

您应该使用外部联接。 select A.ID, A.DataA1, A.DataA2, B.A_ID, B.DataB1, B.DataB2, C.A_ID, C.DataC1, C.DataC2 from A left join B on A.ID = B.A_ID left join C on A.ID = C.A_ID 有关SQL连接的详细解释, 请访问 : http : //www.codinghorror.com...

从父表和子表中删除行(Deleting rows from parent and child tables)

两种可能的方法。 如果您有外键,请将其声明为on-delete-cascade并删除超过30天的父行。 所有的子行将被自动删除。 根据您的描述,看起来您知道要删除的父行并需要删除相应的子行。 你是否像这样尝试过SQL? delete from child_table where parent_id in ( select parent_id from parent_table where updd_tms != (sysdate...

一个父行,另一个表中的多个子行。(One parent row, multiple child rows in another table. How to get them all in one row?)

由于每个父项有一个可变数量的子项,因此在SQL可以完成的唯一方法是在单个记录中分隔所有礼品分号: SELECT p.*, GROUP_CONCAT(c.name, ': ', c.gift1, ', ', c.gift2, ', ', c.gift3 SEPARATOR ';') FROM parents p JOIN children с ON c.parent_id = p.id GROUP BY p.id 这会给你这样的东西: parent ...

SQL父子查询 - 关系在两个表中定义(SQL Parent Child query - relation is defined in two tables)

尝试这个: ;WITH CTE(ID, NAME, PARENT_ID, SORT_ORDER, [Level], ord) AS ( SELECT c.ID, CONVERT(nvarchar(100), c.NAME), c.PARENT_ID, c.SORT_ORDER, 1 [level], CONVERT(nvarchar(255), RIGHT('0000' + CONVERT(nvarchar(255), c.ID), 4)) AS or...

Oracle SQL插入查询 - 进入父表和子表(Oracle SQL insert query - into parent and child tables)

执行此操作的最佳方法之一是使用stored procedure 。 以下程序将为您完成一切。 CREATE OR REPLACE PROCEDURE set_stud_unit( i_fname IN VARCHAR2, i_lname IN VARCHAR2, i_unitid IN VARCHAR2) IS l_studentid student.studentid%TYPE; BEGIN INSERT INT...

简单的SQL来检查父项是否有任何子行(Simple SQL to check if parent has any child rows or not)

为了选择几行 ,这应该是最快的: SELECT o.ID ,o.OrderNum ,CASE WHEN EXISTS (SELECT * FROM dbo.FileHeader f WHERE f.OrderID = o.ID) THEN 1 ELSE 0 END AS FilesHExist FROM Order o; 对于包含大部分 dbo.FileHeader的SELECT,这应该会更好: SELE...

优化python csv处理到父和EAV子表(Optimize python csv processing into parent and EAV child table)

一个有趣的问题,但很难准确回答,因为有许多变量定义了可能适用或不适用的最佳解决方案。 以下是基于以下假设的一种方法 - 您不需要数据库代码可移植。 csv由头部构成,或者至少属性名称是已知和固定的。 产品表中的sku(或name / sku组合)具有唯一约束。 同样,EAV表对product_id和attr_name有唯一约束 推论 - 你没有指定,但我也假设EAV表有一个属性名称的字段。 这个过程归结为 - 通过尽可能最快的路径将数据加载到数据库中 在加载期间或之后,将csv从表格结构展开到EA...

如何查询子表值(How to query child tables values)

尝试这个; var result = poHeaders.Where(e => e.PODetails.Any(a => a.ItemId == intItemId)); Try this; var result = poHeaders.Where(e => e.PODetails.Any(a => a.ItemId == intItemId));

查找具有完全相同的子行集的Sql父行(Find Sql parent rows with exactly same set of child rows)

这是一种方法 - 建立orderid的所有组合,然后使用EXCEPT消除不匹配的订单。 我假设LineNum与'确切'比较无关。 -- Build up all combinations of orders WITH orderPairs AS ( select o1.orderid as orderid1, o2.orderid as orderid2 from orders o1 cross join orders o2 where o...

相关文章

更多

Python解析XML文档

解析XML主要用到pytohn自带的XML库,其次还是lxml库 XML结构,先以一个相对简单但功能 ...

探索 Python,第 1 部分: Python 的内置数值类型

Python 编程语言具有很高的灵活性,它支持多种编程方法,包括过程化的、面向对象的和函数式的。但最重 ...

python2和python3的区别

python2和python3的区别,1.性能 Py3.0运行 pystone benchmark的速 ...

python的下载与安装

python的官网:http://www.python.org/ 有两个版本,就像struts1和st ...

Python资源索引 【转载】

原文地址:http://blog.chinaunix.net/uid-25525723-id-3630 ...

python字典操作

python里的字典就像java里的HashMap,以键值对的方式存在并操作,其特点如下:通过键来存取 ...

【转帖】Python 资源索引

原文地址:http://wiki.woodpecker.org.cn/moin/ObpLovelyPy ...

Python内建函数(A)

abs(x) 说明:abs(x)返回x的绝对值,如果参数是复数,则返回复数的模; 参数x:整 ...

Python的文件类型

Python的文件类型 Python有三种文件类型,分别是源代码文件、字节码文件和优化代码文件 源代 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本