Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在易趣摘要中指定列表标题_Python 3.x_Beautifulsoup_Python Requests_Screen Scraping - Fatal编程技术网

Python 3.x 在易趣摘要中指定列表标题

Python 3.x 在易趣摘要中指定列表标题,python-3.x,beautifulsoup,python-requests,screen-scraping,Python 3.x,Beautifulsoup,Python Requests,Screen Scraping,我对编程和计算机都是新手。我有一点 基本知识,我正在努力做一件我一直在做的事情 r = requests.get(url) soup = BeautifulSoup(r.content, 'lxml') titles = soup.find_all('a', {'class':'vip'}) titles = str(titles) print(titles) 此代码返回如下列表: [ <a class="vip" href="http://www.ebay.com/itm/HAYNE

我对编程和计算机都是新手。我有一点 基本知识,我正在努力做一件我一直在做的事情

r = requests.get(url)
soup = BeautifulSoup(r.content, 'lxml')

titles = soup.find_all('a', {'class':'vip'})
titles = str(titles)
print(titles)
此代码返回如下列表:

[
<a class="vip" href="http://www.ebay.com/itm/HAYNES-HONDA-CIVIC-DEL-SOL-1991-1995-REPAIR-MANUAL-/121848077988?hash=item1c5eb61ea4:g:M5gAAOSwf-VWahyW&amp;vxp=mtr" title="Click this link to access HAYNES HONDA CIVIC DEL SOL 1991-1995 REPAIR MANUAL">HAYNES HONDA CIVIC DEL SOL 1991-1995 REPAIR MANUAL</a>, 

<a class="vip" href="http://www.ebay.com/itm/1992-1995-HONDA-CIVIC-DEL-SOL-FUSE-BOX-/320502127733?hash=item4a9f6a5c75:m:mHAEk2bNyOI4W8-qUiEnGWw&amp;vxp=mtr" title="Click this link to access 1992 - 1995 HONDA CIVIC/DEL SOL FUSE BOX">1992 - 1995 HONDA CIVIC/DEL SOL FUSE BOX</a>, 

<a class="vip" href="http://www.ebay.com/itm/HAYNES-HONDA-CIVIC-DEL-SOL-1991-1995-REPAIR-MANUAL-/111847121189?hash=item1a0a9ba125:g:M5gAAOSwf-VWahyW&amp;vxp=mtr" title="Click this link to access HAYNES HONDA CIVIC DEL SOL 1991-1995 REPAIR MANUAL">HAYNES HONDA CIVIC DEL SOL 1991-1995 REPAIR MANUAL</a>,

<a class="vip" href="http://www.ebay.com/itm/1996-2000-HONDA-CIVIC-DEL-SOL-all-models-repair-manual-/401035736130?hash=item5d5f97b442:g:UjAAAOSwxN5WXm-M&amp;vxp=mtr" title="Click this link to access 1996-2000 HONDA CIVIC &amp; DEL SOL - all models - repair manual">1996-2000 HONDA CIVIC &amp; DEL SOL - all models - repair manual</a>, 

<a class="vip" href="http://www.ebay.com/itm/Haynes-42024-1992-1995-Honda-Civic-and-del-sol-repair-manual-/321920364888?hash=item4af3f2f158:g:9GoAAOSwLzdWRog0&amp;vxp=mtr" title="Click this link to access Haynes 42024 1992-1995 Honda Civic and del sol repair manual.">Haynes 42024 1992-1995 Honda Civic and del sol repair manual.</a>, 

<a class="vip" href="http://www.ebay.com/itm/1988-2000-honda-acura-civic-integra-del-sol-pvc-valve-17130-pm6-003-oem-a137-/141782449307?hash=item2102e47c9b:g:iB8AAOSw0HVWAg5x&amp;vxp=mtr" title="Click this link to access 1988-2000 honda acura civic integra del sol pvc valve 17130-pm6-003 oem a137">1988-2000 honda acura civic integra del sol pvc valve 17130-pm6-003 oem a137</a>, 

<a class="vip" href="http://www.ebay.com/itm/88-2000-Honda-Civic-5-Speed-Manual-Shift-Knob-OEM-CRX-EF-EG-Si-Del-Sol-89-96-/262152990857?hash=item3d09893089:g:1x4AAOSwlV9WT7fj&amp;vxp=mtr" title="Click this link to access 88 - 2000 Honda Civic 5 Speed Manual Shift Knob OEM CRX EF EG Si Del Sol 89 96">88 - 2000 Honda Civic 5 Speed Manual Shift Knob OEM CRX EF EG Si Del Sol 89 96</a>, 

<a class="vip" href="http://www.ebay.com/itm/1988-2000-Honda-Civic-CRX-EF-SI-DX-HF-Del-Sol-Manual-Shift-Knob-OEM-88-91-/281859356536?hash=item41a0207778:g:XTAAAOSwMmBVj5mr&amp;vxp=mtr" title="Click this link to access 1988-2000 Honda Civic CRX EF SI DX HF Del Sol Manual Shift Knob OEM 88-91">1988-2000 Honda Civic CRX EF SI DX HF Del Sol Manual Shift Knob OEM 88-91</a>, 

<a class="vip" href="http://www.ebay.com/itm/Chilton-Repair-Manual-Honda-Civic-Del-Sol-1996-00-/262123397570?hash=item3d07c5a1c2:g:decAAOSwA4dWNs07&amp;vxp=mtr" title="Click this link to access Chilton Repair Manual Honda Civic &amp; Del Sol, 1996-00">Chilton Repair Manual Honda Civic &amp; Del Sol, 1996-00</a>
]
如果您注意到,每行中有两个位置显示标题。首先

"title=Click this link to access..." 
然后就在它后面,走到队伍的尽头。 我尝试使用string.split()和其他变体,但我不知道如何使用它,只指定标题中的单词。我不断地得到不同的单词,每行一个字母,或者只是整个列表项,等等


有人知道一个好方法吗?

您需要为找到的每个元素调用
。get_text()

[a.get_text() for a in soup.find_all('a', {'class': 'vip'})]

我建议您加入易趣开发者计划并使用他们的API。这是更好的和免费的@indianhearts提供的代码将使用
class=“vip”
a
元素上循环,并获取找到的每个元素的文本。有什么问题?谢谢
[a.get_text() for a in soup.find_all('a', {'class': 'vip'})]